.animte( animation_params_json )
.animate() function animates all the matched HTML Elements in Nedil Objects. It takes animation parameters as input and returns an 'ID' called animation Id which can be used for future reference of the animation.
.animate() function is applied to Nedil.Objs.
Animation control parameters (animation_params_json) should be given for all .animate() function.
Eg: { from : { x : 100}, to : { x : 200}, anim : "Location.bounce.easeout.return", duration : 2000, repeat : 5, oncomplete : function() { }, onframe : function() {} }
Parameters
Allowed values for animation_params_json
Following are the allowed values in animation control
Returns
Methods to Stop animation on $.Animator
Example 1 - A Simple Animation
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { // animate x to 200 in 1 sec $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth", duration : 1000 }); }); });
Result
Example 2 - return to the 'from' (start) position
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { //return to the from state $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth.return", duration : 2000 }); }); });
Result
Example 3 - Repeat animation for 'n' number of times
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { // repeat animation 3 times $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth.return", repeat : 3, duration : 2000 }); }); });
Result
Example 4 - Repeat animation for 'infinity'
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { // repeat animation 3 times $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth.return", repeat : -1, duration : 2000 }); }); });
Result
Example 5 - Stop all animations
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { $.get("#box1").animate({ to : { x : 200 }, anim : "Location.smooth.return", repeat : -1, duration : 2000 }); $.get("#box2").animate({ to : { x : 400 }, anim : "Location.smooth.return", repeat : -1, duration : 5000 }); }); $.get("#stpall").on("click", function() { //Stop currently executing animations $.Animator.stopAllAnimation(); }); }); ;
Result
Example 6 - Stop a specific animation using animation ID
JS
HTML
CSS
$.domLoaded(function() { var an1, an2; $.get("#ani").on("click", function() { an1 = $.get("#box1").animate({ to : { x : 200 }, anim : "Location.smooth.return", repeat : -1, duration : 2000 }); an2 = $.get("#box2").animate({ to : { x : 400 }, anim : "Location.smooth.return", repeat : -1, duration : 5000 }); }); $.get("#stpall").on("click", function() { //Stop only the specified animation $.Animator.stop(an1); }); }); ;
Result
Example 7 - Stop the repetition of a specidied animation using animation_id
JS
HTML
CSS
$.domLoaded(function() { var an1, an2; $.get("#ani").on("click", function() { an1 = $.get("#box1").animate({ to : { x : 200 }, anim : "Location.smooth.return", repeat : -1, duration : 2000 }); an2 = $.get("#box2").animate({ to : { x : 400 }, anim : "Location.smooth.return", repeat : -1, duration : 5000 }); }); $.get("#stpall").on("click", function() { //Stop repetition of an animation $.Animator.stopRepeat(an1); }); }); ;
Result
Example 8 - oncomplete callback function
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { // callback function once animation is completed $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth", duration : 1000, oncomplete : function() { alert("Animation is completed"); } }); }); });
Result
Example 9 - onframe function which will be called for every frame of the animation
JS
HTML
CSS
$.domLoaded(function() { $.get("#ani").on("click", function() { // onframe function $.get("#box").animate({ to : { x : 200 }, anim : "Location.smooth.return", duration : 2000, onframe : function() { $.get("#msg").html(parseInt($.get("#box").style("left"))); } }); }); });
Result
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||