this wait can be done using jQuery.delay ()
$(document).ready(function FirstAnimation() {
var $dynamicPanel = $(".dynamicPanel");
$dynamicPanel.animate({
opacity: 0,
left: '100'
}, 5000, function () {
alert('first animation complete');
SecondAnimation($dynamicPanel);
});
});
function SecondAnimation(this) {
$(this).delay(5000).animate({
opacity: 1
}, 100, function () {
alert('second animation complete');
FirstAnimation();
});
};
however, you can call the whole function recursive and pass the animation parameters as parameters from the array . This way you reuse the function and only change the behavior.
var animationSettings = [{opacity: 0, left: '100'},{ opacity: 1 }];
var x = 1;
var $dynamicPanel = $(".dynamicPanel");
(function animate(){
x = x == 1 ? 0 : 1;
$dynamicPanel.delay(x * 5000).animate(animationSettings[x],
1000,
function () {
animate();
});
}());
the violin is here
source
share