jQuery - call function when animate

风流意气都作罢 提交于 2019-12-06 07:41:25

you could use its step function, like:

selector['el']['box'].animate({width:selector['el']['box'].width() - 250}, 500,
step: function( currentStep ){       
    //step animation complete
   //do something here
});

See :: step in animate()

step function is ur solution here is what jquery documentation says

step

Type: Function( Number now, Tween tween ) A function to be called for each animated property of each animated element. This function provides an opportunity to modify the Tween object to change the value of the property before it is set.

See this DEMO you will see width properties changing step wise

$( "div").css({
    position: "fixed",
    left: "50px"
})
.animate(
{
    width: 1000
},
{
    duration: 500,
    step: function( currentLeft, animProperties ){
        $( "span" ).html( $( "span" ).html()+"<br>value:"+currentLeft+" state:"+animProperties);
        console.log( "Left: ", currentLeft );
    }
});
  selector['el']['box'].animate({
          // for example 
          opacity: 0.25,
          left: '+=50',
          height: 'toggle'
        },
        {
        duration: 500,
        step: function() {
          //add your code here
        });

Add your code to second function block.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!