javascript - jQuery animation doesn't run fluently -


i learning how schedule animations via javascript, of jquery. tried blink h1 tags, animation doesn't seem run fluently. stops while , go on.
core animation code:

function animslideheading() {   $('.slide h1').animate({     opacity: .6   }, 500, 'swing', function() {     $('.slide h1').animate({       opacity: 1     }, 500, 'swing', animslideheading);   }); } 

see this jsbin.

there several elements matching selector $('.slide h1'), callback called multiple times, once each element animated, , animslideheading runs more , more times longer goes, messing up.

to solve it, can use promises resolve when animations have completed elements in collection collectively

function animslideheading() {     $('.slide h1').animate({         opacity: 0.6     }, 500, 'swing').promise().done(function () {         $(this).animate({             opacity: 1         }, 500, 'swing').promise().done(animslideheading);     }); } animslideheading(); 

fiddle


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -