Angular Animate: slide in div from right side - angularjs

In this plunk I am trying to have a div slide in from the right side, then slide back to hide. Clicking on the checkbox shows/hides the div.
I almost made this work, I cannot make the transition to slide, the div just shows up and hides without transitioning. Any ideas?
HTML:
Show <input type="checkbox" ng-model="checked">
<div class="panel" ng-show="checked" style="border:1px solid #dddddd;background:orange;width:200px">
<input type="checkbox"> Charts
<br/>
<input type="checkbox"> Reports
<br/>
<input type="checkbox"> Files
<br/>
</div>
CSS:
.panel{
position: fixed;
top: 10px;
right: -2px;
}
.panel.ng-show-add {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
}
.panel.ng-show-add-active {
display: block;
}

Firstly, to use ngShow animations, you need ngAnimate, so I added that.
I also updated the plunker to use a newer version of angular for the sake of ease and compatibility. If you are using an older version of angular, just use the appropriate version of ngAnimate.
You need this to make it apply the styles correctly (per the docs):
.panel.ng-hide-add, .panel.ng-hide-remove {
/* this is required as of 1.3x to properly
apply all styling in a show/hide animation */
transition: 0s linear all;
}
Then you need to make sure you apply your transitions to the active add and active remove for hide:
.panel.ng-hide-add-active, .panel.ng-hide-remove-active {
/* -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
*/
transition: all ease-in-out 2s;
}
Note that I left your cubic-bezier transitions in there for reference, but have them commented out just to get things working.
I then added a hidden (start) position for it.
.panel.ng-hide {
right: -200px;
}
So...not sure if this works for you, but you said you needed it to slide, so it does that. Not sure why you need the cubic-bezier transition for that, though I am not that familiar with it.
Animation Demo
As an aside, angular doesn't animate through an ng-show class, it does it through ng-hide, thus the ng-hide-remove/ng-hide-add and the -active versions of those classes. It may be confusing if you try to use those and wonder why things aren't working. It's because they don't get used.

Related

Moving (instead of showing) div in Angular animation

In this plunk I have an Angular animation that shows up and slides in a div from the right. What I need is a 'drawer' effect where the div edge is shown for the user to click on it, and only then the div will slide in. This means that initially the div should be partially shown. Since the original animation is done from hide to show (instead of from show to show) I don't know how to approach this. Any ideas?
CSS:
.panel{
position: fixed;
top: 10px;
right: -2px;
}
.panel.ng-hide {
right: -200px;
}
.panel.ng-hide-add, .panel.ng-hide-remove {
/* this is required as of 1.3x to properly
apply all styling in a show/hide animation */
transition: 0s linear all;
}
.panel.ng-hide-add-active, .panel.ng-hide-remove-active {
/* -webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 2s;
*/
transition: all ease-in-out 2s;
}
.panel.ng-show-add-active {
display: block;
}
HTML:
Show <input type="checkbox" ng-model="checked" />
<div class="panel" ng-show="checked"
style="border:1px solid #dddddd;background:orange;width:200px">
<input type="checkbox" /> Charts <br />
<input type="checkbox" /> Reports <br />
<input type="checkbox" /> Files <br />
</div>
If you want something like the SideNav on Android, you should try Angular Material and use the already implemented SideNav instead of creating your own.
If not, try to translate the div by adding this to your CSS:
div {
transform: translate(-50px,0px);
}

ngRepeat Animation in angular 1.4

i am tying to achieve an Animation in Angular JS 1.4.0, which i'd like to be similar to the one, which can be found on this page (Angular 1.1.5):
http://www.nganimate.org/angularjs/ng-repeat/move
As I understand, there have been major changes to ngAnimate over the last few Versions.
I have recreated the important Part of my application with Plunkr. It can be found here http://plnkr.co/edit/9DK3LEAaGDgDT2kIILjG?p=preview
I want the Items, that show and hide, because of a different filter input, to be animated with a css animation.
This is my filter input:
<input type="text" class="form-control" ng-model="search">
And this is the list, in which all the Elements from the search show up.
<ul>
<li ng-class="item" ng-repeat="name in people | filter:search">
{{name.name}}
</li>
</ul>
Here are my CSS animations:
.item.ng-enter,
.item.ng-leave
{
-webkit-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-moz-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-ms-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-o-transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
transition: 400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
position: relative;
display: block;
}
.item.ng-enter.item.ng-enter-active,
.item.ng-leave {
opacity: 1;
top: 0;
height: 30px;
}
.item.ng-leave.item.ng-leave-active,
.item.ng-enter {
opacity: 0;
top: -50px;
height: 0px;
}
The search and filters work fine, but the CSS animations are not triggered.
I would be very glad, if someone had a solution to this problem!
The latest version like angular 1.4 the approach is bit different. First of all you should include angular animate js.
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.0-rc.2/angular-animate.js"></script>
Then you should inject 'ngAnimate' to module like this.
var app = angular.module('myApp', ['ngAnimate']);
also use class like this in along with ng-reapeat
<li class="animate-repeat" ng-repeat="friend in friends | filter:q as results">
also use css for animate like below
.animate-repeat {
line-height:40px;
list-style:none;
box-sizing:border-box;
}
.animate-repeat.ng-move,
.animate-repeat.ng-enter,
.animate-repeat.ng-leave {
-webkit-transition:all linear 0.5s;
transition:all linear 0.5s;
}
.animate-repeat.ng-leave.ng-leave-active,
.animate-repeat.ng-move,
.animate-repeat.ng-enter {
opacity:0;
max-height:0;
}
.animate-repeat.ng-leave,
.animate-repeat.ng-move.ng-move-active,
.animate-repeat.ng-enter.ng-enter-active {
opacity:1;
max-height:40px;
}
more references

ng-Animate not working for a Hide and Show setting

I'm using AngularJS version 1.2.11. I've set a toolbar to slide in and out with a transition using ng-Animate (show and hide).
Here is the HTML:
<div>
<div class="full-height">
<menu-main class="full-height pull-left"></menu-main>
<menu-sub class="full-height pull-left" ng-show="data.active" ng-animate="'animate'">
</menu-sub>
</div>
</div>
And here is the CSS for the same toolbar element
.animate.fade-hide, .animate..fade-show {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 3.5s;
}
.animate.fade-hide, {
position: fixed;
top: 500px;
opacity: 0.3;
}
.animate.fade-hide, .animate.fade-hide-active
{
position: fixed;
top: 500px;
opacity: 0.3;
}
.animate.fade-show {
position: fixed;
top: 100px;
opacity: 1;
}
.animate.fade-show, .animate.fade-show-active {
position: fixed;
top: 100px;
opacity: 1;
}
The animation does not work, and I'm not sure if I'm doing this correctly.
The ng-animate attribute is deprecated in 1.2 and no longer used. Instead, animations are now class based.
Also make sure you are referencing angular-animate.js and adding ngAnimate as a dependent module:
var app = angular.module('myApp', ['ngAnimate']);
You then name your animations, for example 'fadein' and 'fadeout', and decorate them with some additional classes following a special naming convention that can be found in the Angular documentation.
Another good source on the topic is Year of moo.
Fadein example:
/* After the transition this will be the only class remaining */
.fadein {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 1.5s;
opacity: 1; /* Default value but added for clarity */
}
/* Initial state when showing */
.fadein.ng-hide-remove {
opacity: 0;
display: block !important;
}
/* Will transition towards this state */
.fadein.ng-hide-remove.ng-hide-remove-active {
opacity: 1;
}
Demo: http://plnkr.co/edit/V9w2EwUh0unszf62TZZB?p=preview

Animating Bootstrap Open and close animation - angular

I'm using twitter bootstrap modal window in angular and wanted to have animations when the modal window shows up and when it is closed. I tried nganimate but it doesn't seem to work.
CSS
.slide-enter-setup, .slide-leave-setup {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
}
.slide-enter-setup {
position:absolute;
left:0;
top:-200px;
}
.slide-enter-start {
top:0;
}
.slide-leave-setup {
position:absolute;
top:0;
}
.slide-leave-start {
top:200px;
}
JS
angular.module("template/modal/window.html", []).run(["$templateCache", function($templateCache) {
$templateCache.put("template/modal/window.html",
"<div ng-animate=\"slide\" class=\"modal{{ windowClass }}\" ng-class=\"{in: animate}\" ng-style=\"{'z-index': 1050 + index*10}\" ng-transclude></div>");
}]);
Plnkr - http://plnkr.co/edit/D1tMRpxVzn51g18Adnp8?p=preview
You're using AngularJS 1.2.x, but your CSS code follows the older convention. Read this article and update your CSS code: http://www.yearofmoo.com/2013/08/remastered-animation-in-angularjs-1-2.html

Angularjs ng-animate + css transition for sliding effect

I'm trying to achieve sliding effect with the new ng-animate feature of Angular. I've taken some code from the demo site and have prepared a fiddle.
The problem is that elements below the sliding DIV keeps shifting up and down when the item is being swapped from the array. I tried with line-height but no success.
Is it possible to fix the above behavior? or any better way to achieve it only with angular and CSS?
You can wrap the input and the button in a div and also put it in the absolute position.
Here is a demo
HTML
<div ng-app="">
<div ng-controller='anim' >
<div ng-repeat="item in lst" ng-animate=" 'wave' ">
{{item}}
</div>
<div class="wrapperInput">
<input ng-model="cmt">
<button ng-click="clk()"> Slide </button>
</div>
</div>
</div>
CSS
</style> <!-- Ugly Hack due to jsFiddle issue: http://goo.gl/BUfGZ -->
<script src="http://code.angularjs.org/1.1.4/angular.min.js"></script>
<style>
/**/
.wrapperInput{position:absolute;top:30px;}
/**/
.wave-enter-setup, .wave-leave-setup {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) .5s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) .5s;
line-height:100%;
}
.wave-enter-setup {
position:relative;
left:100%;
line-height:100%;
}
.wave-enter-start {
left:0;
line-height:100%;
}
.wave-leave-setup {
position:absolute;
left:0;
line-height: 100%;
}
.wave-leave-start {
left:-100%;
line-height: 10%;
}
JS
function anim($scope,$timeout){
$scope.lst = [];
$scope.master = ['[1] John who is 25 years old.','[2] Jessie who is 30 years old.','[3] Johanna who is 28 years old.','[4] Joy who is 15 years old.','[5] Mary who is 28 years old.','[6] Peter who is 95 years old.','[7] Sebastian who is 50 years old.','[8] Erika who is 27 years old.','[9] Patrick who is 40 years old.','[10] Samantha who is 60 years old.'];
$scope.lst.unshift($scope.master[Math.floor((Math.random()*10)+1)]);
$scope.clk = function() { clik();}
function clik() {
//alert('here');
$scope.lst.unshift($scope.master[Math.floor((Math.random()*10)+1)]);
$scope.lst.pop();
$timeout(function(){ clik();},2000);
}
clik();
};
Try this :
CSS:
.wave-enter-setup, .wave-leave-setup {
-webkit-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) .5s;
-moz-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
-o-transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) 0.5s;
transition:all cubic-bezier(0.250, 0.460, 0.450, 0.940) .5s;
position:relative;
display:table;
float:left;
}
.wave-enter-setup {
left:100%;
}
.wave-enter-start {
left:0;
}
.wave-leave-setup {
left:0%;
}
.wave-leave-setup.wave-leave-start {
left:-100%;
}
.floatNone{ clear:both; position:relative;}
HTML:
<div ng-app="">
<div ng-controller='anim' >
<div ng-repeat="item in lst" ng-animate=" 'wave' " >{{item}}</div>
<div class="floatNone">
<input ng-model="cmt" >
<button ng-click="clk()"> Slide </button>
</div>
</div>
</div>

Resources