我可以从每个步骤的 jQuery 动画步骤方法中获得哪些信息?

发布于 2024-09-09 17:11:42 字数 1002 浏览 1 评论 0原文


我有一个垂直的推荐带,我有这个方法,每隔几秒用计算值(取决于当前推荐的高度)为其 top 值设置动画。

现在,当用户将鼠标悬停在其上时,它会立即停止(通过 .stop() ,并且还通过 clearInterval(idOfinterval) 清除间隔
但我仍然想知道在突然停止之前它还剩下多少像素可以进行动画处理。

所以我查了一下文档,我发现有一个步骤 具有回调的方法,可以为我提供有关动画每个(?)步骤的信息。

查看部分代码

 //in middle of a object literal
  animate:function(){
    animAmmount = someCalculation;
    testimonialsBelt.parentElment.animate({
    top:"-="+howMuchIsLeft||animAmmount+"px"},
    {step:function(step){
         //here i am trying to get how much px it has moved so far
           currTopVal = step;
           console.log("currTopVal", currTopVal);
        // i get some numbers, and i have no idea from where it got them 
       }
   },
   calculatedSpeed);
}

所以我的主要问题是

  • 我可以从传递给 step 方法的参数中获取哪些信息?
  • 它是否会在动画的每个间隔回调?
  • I got a vertical testimonials belt and i have this method that animates its top value with a calculated value (depending on the height of the current testimonial) every few seconds.

    Now when a user hovers over it, it stops right away (via .stop() and also the interval is cleared via clearInterval(idOfinterval)
    But i still want to know how much more pixels it had left to animate before it suddenly got halted.

    So i looked up in the documentation and i see that there is a step method that has a callback and can give me information on each(?) step of the animation.

    see part of the code

     //in middle of a object literal
      animate:function(){
        animAmmount = someCalculation;
        testimonialsBelt.parentElment.animate({
        top:"-="+howMuchIsLeft||animAmmount+"px"},
        {step:function(step){
             //here i am trying to get how much px it has moved so far
               currTopVal = step;
               console.log("currTopVal", currTopVal);
            // i get some numbers, and i have no idea from where it got them 
           }
       },
       calculatedSpeed);
    }
    

    So my main questions are

  • What information can i get from parameters passed in to the step method?
  • and does it callback on each interval of an animation?
  • 如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    生死何惧 2024-09-16 17:11:42

    看起来“this”符号将是调用 animate 的元素。回调的第一个参数看起来像在此步骤中动画的属性值。第二个参数是一个对象,如下所示:

    • elem:元素 animate 在
    • end 上被调用:(猜测)动画完成时属性的值
    • now:(猜测)此步骤中属性的值
    • options:您传递给 animate 的原始选项。
    • pos:(猜测)某物的位置
    • prop:(猜测)该属性在此步骤中起作用。如果有多个属性更改,则每个属性可能都有一个步骤。
    • start:(猜测)动画开始时属性的值
    • startTime:(猜测)动画开始的时间(以毫秒为单位)。
    • 状态:从 0 到 1 的浮点数,指示动画距离完成的程度。
    • 单位:属性值的单位(例如“px”)。

    It looks like the "this" symbol will be the element animate was called on. The first parameter to the callback looks like the value of the property animated on this step. The second parameter is an object that looks like this:

    • elem: the element animate was called on
    • end: (guess) the value of the property when animation is complete
    • now: (guess) the value of the property in this step
    • options: the original options you passed into animate.
    • pos: (guess) the position of something
    • prop: (guess) the property acted on in this step. If there are multiple property changes, there is probably a step for each one.
    • start: (guess) the value of the property when animation was started
    • startTime: (guess) the time in ms the animation started.
    • state: A float from 0 to 1 that indicates how close to completion the animation is.
    • unit: the unit of the property value (e.g. 'px').
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文