How to delay a j-query rotation animation
I have a div element rotating back and forth a set number of times, using
the following code:
$(document).ready(function(){
var rotation = function (times) {
var el = $("#pencil");
if(typeof times == 'number'){
el.data('repeatRotation',times);
} else {
times = el.data('repeatRotation')-1;
el.data('repeatRotation',times);
}
if(times > 0){
$("#pencil").rotate({
angle: 0,
animateTo: 2,
duration: 200,
callback: rotationBack
});
}
}
var rotationBack = function () {
$("#pencil").rotate({
angle: 0,
animateTo: -2,
duration: 200,
callback: rotation
});
}
rotation(10);
});
What I actually want is the div element to start roatating after a 5
second delay. I tried adding the usual .delay(5000) to the above code, as
shown below, but it does not seem to make a difference, the code still
executes immediately after the page loads:
if(times > 0){
$("#pencil").delay(5000).rotate({
angle: 0,
animateTo: 2,
duration: 200,
callback: rotationBack
});
Does anyone know why the .delay(5000) is not working in this case?
No comments:
Post a Comment