ngAnimate angularjs and bootstrap - angularjs

I do an app with Angularjs and ui.Bootstrap
I use a $routeProvider so I have an <ng-view></ng-view> in my main page,
with animate.css, I want to animate enter and leave of my view, but bootstrap doesn't had both class ( .myclass-enter and .myclass-leave )
I don't know why?

This is not responsibility of Bootstrap to animate ng-view element. But you can easily achieve this with ngAnimate module (remember to inject it into your main app module). All you need to do is to implement couple of classes.
For example to make view slide you can write this classess:
<div ng-view class="slide"></div>
and CSS:
.slide {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.slide.ng-enter,
.slide.ng-leave {
transition: all 1s ease;
}
.slide.ng-enter {
left: 100%;
}
.slide.ng-enter-active,
.slide.ng-leave {
left: 0;
}
.slide.ng-leave-active {
left: -100%;
}
Here is some examples I put together of this approach.

thinx I think I forget vendor prefix on my css class, so it works with animate.css now
.slide.ng-enter,
.slide.ng-leave {
}
.slide.ng-enter {
animation-delay: 1s;
}
.slide.ng-enter-active {
-webkit-animation-name: bounceIn;
animation-name: bounceIn;
}
.slide.ng-leave {
}
.slide.ng-leave-active {
-webkit-animation-name: hinge;
animation-name: hinge;
}

Related

How to hide with animation? React + SCSS

I think is just something very simple, but I can't think of anything;
import React, { useState } from "react"
import "./header.scss"
export default function(){
let [curtain, setCurtain] = useState(false);
return (
<div className="header"
onMouseEnter={() => setCurtain(true)}
onMouseLeave={() => setCurtain(false)}
>
{ curtain && <div className="header__curtain__black header__curtain"/> }
</div>
)
}
And here is SCSS
.header{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 70px;
&__curtain{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: black;
animation: slide_down 0.2s linear;
}
}
#keyframes slide_down {
0%{
transform: translateY(-100%);
}
100%{
transform: translateY(0);
}
}
Code is super simple and task is super simple too, I want to make a reverse on closing but what do I do ?
You can assign different class names to the curtain div according to curtain state value. I would also suggest to use transition property in your css styles instead of keyframe animations.
Here is the edited code.

AngularJS animation from 1.1.5 to 1.5.1 slide in issues

I'm trying to do a slide in animation when ng-show is invoked.
The element will slide in from the right.
If I'm using 1.1.5 , it works perfectly as show in this fiddle (https://jsfiddle.net/sbcjdqwk/1/)
I understand that ng-animate has been deprecated since 1.2 and I have made the necessary adjustments for 1.5.5.
.slide.ng-enter {
position: relative;
left: -100%;
}
.slide.ng-enter.ng-enter-active {
transition: all 1s;
left: 0;
}
.slide.ng-leave {
position: relative;
left: 0;
}
.slide.ng-leave.ng-leave-active {
transition: all 1s;
left: -100%;
}
Somehow it's still not working. Could anyone please advise? Thanks!
Fiddle here: https://jsfiddle.net/xrp1h592/3/
.animate-show-hide.ng-hide-remove {
left: 100%;
position: relative;
}
.animate-show-hide.ng-hide-remove-active {
left: 0;
}
.animate-show-hide.ng-hide-add {
left: 0%;
position: relative;
}
.animate-show-hide.ng-hide-add-active {
left:100%;
}
.animate-show-hide.ng-hide-add,
.animate-show-hide.ng-hide-remove {
transition: ease-in-out 300ms;
}
Using ng-hide-add and ng-hide-remove solves the issue.
And using "ease-in-out" rather than "linear" makes it more smooth.
Plunkr link here:
https://plnkr.co/edit/FeX0hG6nXnVz4h3H9oow?p=preview

angular ng-class appending classes does not trigger css3 transition

I have created custom modal directive in angular but it seems transition is not working and i can't figure out why.
Inside my directive isolated scope i have method toggleModal() which is switching modalState to true / false. So everything is basically working except animation
HTML:
<span class="glyphicon glyphicon-edit" ng-click="toggleModal()"></span>
<div class="annotation-panel"
ng-class="{'annotation-panel-active' : modalState == true, 'annotation-panel-inactive' : modalState == false}">
<div class="annotation-modal" ng-class="{'active':modalState == true, 'inactive':modalState == false}">
<button type="button" class="btn btn-default" ng-click="toggleModal()">Close</button>
</div>
</div>
CSS:
.annotation-panel{
display: none;
position: fixed;
top:0;
left:0;
z-index: 1000;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
}
.annotation-panel-active{
display: block!important;
}
.annotation-panel-inactive{
display: none!important;
}
.annotation-modal{
position: fixed;
z-index: 1001;
left:10vw;
top: 0;
width: 80vw;
height: auto;
overflow-y: scroll;
opacity: 0;
background-color: whitesmoke;
transition: all 0.5s linear;
}
.annotation-modal.active{
top: 10vh;
opacity: 1;
}
.annotation-modal.inactive{
top: 0;
opacity: 0;
}
So basically using ng-class im switching between two classes
.active and .inactive but it seems transition does not animate the change in the classes, i think i have some general mistake but can't find it. I don't use ngAnimate because i'm making module so i don't a lot of dependencies and that's why i'm making it custom with classes
You are hiding the annotation-panel with display:none instantly when the state changes to inactive, so the contained annotation-modal wont be visible.
The use of ng-animate here would be to only apply ng-hide (and thus, display:none) when the animation has finished.
Without that, you need to use a different method to hide the panel after the animation has finished. Here is one solution with moving the panel offscreen. Notice how the transition-delay in inactive state matches the animation length of the modal fadeout. Also, by only having the transition on the inactive state, when the panel becomes active, it moves instantly to the viewport.
.annotation-panel{
position: fixed;
top: -2000px;
left: 0;
z-index: 1000;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
}
.annotation-panel-active{
top: 0;
}
.annotation-panel-inactive{
transition-property: top;
transition-delay: 0.5s;
transition-duration: 0s;
}
.annotation-panel{
position: fixed;
top: -2000px;
left: 0;
z-index: 1000;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.7);
}
.annotation-panel-active{
top: 0;
}
.annotation-panel-inactive{
transition-property: top;
transition-delay: 0.5s;
transition-duration: 0s;
}
.annotation-modal{
position: fixed;
z-index: 1001;
left:10vw;
top: 0;
width: 80vw;
height: auto;
overflow-y: scroll;
opacity: 0;
background-color: whitesmoke;
transition: all 0.5s linear;
}
.annotation-modal.active{
top: 10vh;
opacity: 1;
}
.annotation-modal.inactive{
top: 0;
opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<span class="glyphicon glyphicon-edit" ng-click="modalState =!modalState">click</span>
<div class="annotation-panel"
ng-class="{'annotation-panel-active' : modalState == true, 'annotation-panel-inactive' : modalState == false}">
<div class="annotation-modal" ng-class="{'active':modalState == true, 'inactive':modalState == false}"> helloo
<button type="button" class="btn btn-default" ng-click="modalState = false">Close</button>
</div>
</div>
</div>
You should go for ng-hide if you just have to make display none for the element
here are some animation css for that
//
//a working example can be found at the bottom of this page
//
.my-element.ng-hide-add, .my-element.ng-hide-remove {
/* this is required as of 1.3x to properly
apply all styling in a show/hide animation */
transition: 0s linear all;
}
.my-element.ng-hide-add-active,
.my-element.ng-hide-remove-active {
/* the transition is defined in the active class */
transition: 1s linear all;
}
.my-element.ng-hide-add { ... }
.my-element.ng-hide-add.ng-hide-add-active { ... }
.my-element.ng-hide-remove { ... }
.my-element.ng-hide-remove.ng-hide-remove-active { ... }
Link for more details animations

CSS Sliding views with ui-router

I am trying to achieve the same effect of sliding in/out views as found here:
http://dfsq.github.io/ngView-animation-effects/app/#/page/1
Ive created a plunker: http://plnkr.co/edit/ST49iozWWtYRYRdcGGQL?p=preview
But my entire ui-view completely disappears when i copy the CSS from the link above and think it could be down to the position: relative in my container
CSS:
*,
*:after,
*:before {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
html {
font-size: 62.5%;
min-height: 100%;
position: relative;
}
html body {
font-size: 140%;
line-height: 1.5;
margin: 0;
padding: 0 0;
margin-bottom: 60px;
}
.container {
max-width: 430px;
margin: 0 auto;
position: relative;
display: block;
float: none;
overflow: hidden;
}
.l-one-whole {
width: 100%;
}
form {
background: #f0f0f0;
height: 350px;
padding: 10px;
font-size: 1.4em;
}
CSS needed to add:
.slide {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
.slide.ng-enter,
.slide.ng-leave {
-webkit-transition: all 1s ease;
transition: all 1s ease;
}
.slide.ng-enter {
left: 100%;
}
.slide.ng-enter-active {
left: 0;
}
.slide.ng-leave {
left: 0;
}
.slide.ng-leave-active {
left: -100%;
}
HTML:
<body ng-controller="MainCtrl">
<ul>
<li>view1
</li>
<li>view2
</li>
</ul>
<main class="l-one-whole">
<section class="container">
<article class="l-one-whole">
<div ui-view class="slide"></div>
</article>
</section>
</main>
</body>
JS:
var app = angular.module('plunker', ['ui.router', 'ngAnimate']);
app.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('view1', {
url: '/view1',
templateUrl: 'page1.html'
})
.state('view2', {
url: '/view2',
templateUrl: 'page2.html'
});
$urlRouterProvider.otherwise('/view1');
});
Any help appreciated.
I think this is what you are looking for: Plunkr
I added the following styles to make animations work:
/* Transition effects */
.l-one-whole {
position: relative;
overflow: hidden;
min-height: 400px;
}
.slide {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.slide.ng-enter,
.slide.ng-leave {
transition: all 1s ease;
}
.slide.ng-enter {
transform: translate(100%, 0);
}
.slide.ng-enter-active {
transform: translate(0, 0);
}
.slide.ng-leave {
transform: translate(0, 0);
}
.slide.ng-leave-active {
transform: translate(-100%, 0);
}
I used transform instead of left because AFAIK it enables browser to accelerate animation using GPU increasing performance.
I hope I am not missing anything.
Result: http://plnkr.co/edit/vhGSiA?p=preview
I have use Angular 1.3.15 instead of 1.2.9
Simplified HTML
<section class="container">
<div ui-view class="slide-left"></div>
</section>
and more CSS
.container {
overflow: hidden;
position: relative;
}
.slide-left.ng-enter, .slide-left.ng-leave {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
transition: transform .7s ease-in-out;
}
.slide-left.ng-enter {
z-index: 101;
transform: translateX(100%);
}
.slide-left.ng-enter.ng-enter-active {
transform: translateX(0);
}
.slide-left.ng-leave {
z-index: 100;
transform: translateX(0);
}
.slide-left.ng-leave.ng-leave-active {
transform: translateX(-100%);
}
form { /* contents within ui-view */
position:absolute;
}
Change
<script src="https://raw.github.com/dlukez/ui-router/angular-1.2/release/angular-ui-router.js"></script>
to:
<script src="https://cdn.rawgit.com/dlukez/ui-router/angular-1.2/release/angular-ui-router.js"></script>
Updated plnkr
Detail explaination can be found here:
Link and execute external JavaScript file hosted on GitHub

ngAnimate not working

I'm trying to learn how to use ngAnimate with ngRepeat, but in my example, the items are just showing up instead of animating in.
I included ngAnimate, put it as a dependency in the module, gave my ngRepeat a class of item, and created the following.
.item-ng-enter {
position: relative;
opacity: 0.0;
height: 0;
left: 10px;
}
.item-ng-enter.item-ng-enter-active {
transition: all 0.5s ease;
opacity: 1.0;
left: 0;
height: 18px;
}
Plnkr: http://plnkr.co/edit/EVFUww7dfUAJzQqth7mx
First thing, Angular adds .ng-enter and .ng-enter-active classes so .item-ng-enter and .item-ng-enter-active are incorrect. Second thing you should be adding transition definitions in .ng-animate class which is added before any other angular class:
.item.ng-animate { transition: all 0.5s ease; }

Resources