var app = angular.module('anim', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.value=0;
$scope.update = function(){
$scope.value = $scope.value + 1;
};
});
app.directive('ticker', function() {
return {
link: function(scope, element, attrs) {
var threshold;
var last, deferTimer;
threshold = 800;
scope.$watch(attrs.ticker, function(val, oldVal) {
if(val === oldVal) return;
var flickr = function(element){
element.fadeOut(200);
element.fadeIn(200);
element.fadeOut(200);
element.fadeIn(200);
}
//Throttle excessive updates
var now = +new Date(), args = arguments;
if (last && now < last + threshold) {
// hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function () {
last = now;
flickr(element)
}, threshold);
} else {
last = now;
flickr(element);
}
});
}
}
}
);
<!DOCTYPE html>
<html ng-app="anim">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="jquery@1.9.1" data-semver="1.9.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script data-require="angular.js@1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" data-semver="1.0.8"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<p>Hello {{name}}!</p>
<button ng-click="update()">Update Value</button>
Value Is <span ng-bind="value" class="textStyle" ticker="value"></span>
</body>
</html>
/* Put your css in here */
.textStyle {
font-weight: bolder;
font-size: 45px;
}
Animate a element on model change.