##AngularJS Custom Directives animations using $animate.move
Created
August 7, 2015 11:11
-
-
Save anonymoussc/d01bc7411b13a10f6087 to your computer and use it in GitHub Desktop.
AngularJS Custom Directives animations using $animate.move
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="myApp"> | |
<head> | |
<title>AngularJS Custom Directives animations using $animate.move</title> | |
<link href="style.css" rel="stylesheet"/> | |
</head> | |
<body> | |
<p>Click on any element below to move elements:</p> | |
<div move-directive=""> | |
<div class="element1 moveItem">Element 1</div> | |
<div class="element2 moveItem">Element 2</div> | |
<div class="element3 moveItem">Element 3</div> | |
</div> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-animate.min.js"></script> | |
<script src="script.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('myApp', ['ngAnimate']) | |
.directive('moveDirective', function ($animate) { | |
return { | |
link : function ($scope, $element, $attrs) { | |
var elements = $element.children(); | |
var count = 0; | |
$element.on('click', function () { | |
count++; | |
// Toggle between firstElement and secondElement | |
if (count % 3 == 1) { | |
$animate.move(angular.element(elements[2]), $element); | |
} else if (count % 3 == 2) { | |
$animate.move(angular.element(elements[1]), $element); | |
} else { | |
$animate.move(angular.element(elements[0]), $element); | |
} | |
//Trigger digest in this case, because this listener function is out of the angular world | |
$scope.$apply(); | |
}); | |
} | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* move animation */ | |
.moveItem.ng-move { | |
-webkit-animation : 1s ng-move-repeat-animation; | |
-moz-animation : 1s ng-move-repeat-animation; | |
-ms-animation : 1s ng-move-repeat-animation; | |
-o-animation : 1s ng-move-repeat-animation; | |
animation : 1s ng-move-repeat-animation; | |
} | |
@-webkit-keyframes ng-move-repeat-animation { | |
from { | |
opacity : 1; | |
color : black; | |
} | |
to { | |
opacity : 0.5; | |
color : blue; | |
} | |
} | |
@-moz-keyframes ng-move-repeat-animation { | |
from { | |
opacity : 1; | |
color : black; | |
} | |
to { | |
opacity : 0.5; | |
color : blue; | |
} | |
} | |
@-ms-keyframes ng-move-repeat-animation { | |
from { | |
opacity : 1; | |
color : black; | |
} | |
to { | |
opacity : 0.5; | |
color : blue; | |
} | |
} | |
@-o-keyframes ng-move-repeat-animation { | |
from { | |
opacity : 1; | |
color : black; | |
} | |
to { | |
opacity : 0.5; | |
color : blue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment