JQuery synchronous animation

前端 未结 7 1922
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 07:00

In many cases I wish animation to be executed synchronously. Especially when I wish to make a a series of sequential animations.

Is there an easy way to make a jQuer

7条回答
  •  自闭症患者
    2020-11-29 07:06

    jQuery provides a "step" callback for its .animate() method. You can hook into this to do synchronous animations:

    jQuery('#blat').animate({
      // CSS to change
      height: '0px'
    },
    {
      duration: 2000,
      step: function _stepCallback(now,opts) {
        // Stop browser rounding errors for bounding DOM values (width, height, margin, etc.)
        now = opts.now = Math.round(now);
    
        // Manipulate the width/height of other elements as 'blat' is animated
        jQuery('#foo').css({height: now+'px'});
        jQuery('#bar').css({width: now+'px'});
      },
      complete: function _completeCallback() {
        // Do some other animations when finished...
      }
    }
    

提交回复
热议问题