如何切断jQuery动画的开始? [英] How to cut off the start of a jquery animation?

查看:101
本文介绍了如何切断jQuery动画的开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

别对我好难,这是我第一次发帖。

Don't be hard on me, it's my first time posting.

我目前正在研究命运之轮,该命运之轮与每个连接的设备同步通过node.js和websockets。但是我想切断动画的开始,当用户在轮子已经旋转的情况下加入时,因此它只显示动画的最后几秒钟而不改变其缓动性。

I'm currently working on a wheel of fortune, which is synchronized to each connected device via node.js and websockets. However I want to cut off the start of the animation, when a user joins while the wheel is spinning already, so it would only show the last seconds of the animation without changing it's easing.

jquery动画由一个简单的步进动画组成,该动画会旋转轮子。我已经尝试过更改步骤 fx对象的参数,例如fx.start或fx.pos。尽管fx.start只是动画开始的变量,例如180度,而fx.pos只是一种输出参数,可以将某些内容更改为动画中的给定时间,例如文本颜色或其他内容。但是不能更改fx.pos的值,也不能更改当前设置动画的位置。我创建了一个函数,使命运之轮旋转两次,然后以给定的角度停止。

The jquery animation is made of a simple step animation, which rotates the wheel around. I already tried to change the parameters of the step's 'fx' object like fx.start or fx.pos. While fx.start only being the variable at which point the animation started, for example 180 degrees and fx.pos is only a sort of output parameter to change something to a given time in the animation, like a text color or something. However the fx.pos value can't be changed nor changes the position the animation is currently set in. I created a function to rotate the wheel of fortune two times and then it stops at a given degree.

我也尝试更改了缓动,因此它是50%线性,50%摆动,但这使动画看起来很杂乱,因为起初它以恒定的速度旋转,然后突然旋转得更快

Also I tried to change the easing, so it would be 50% linear, 50% swing, but this makes the animation look trashy, since at first it's spins at a constant speed and suddenly it spins faster than slower.

function spinRoulette(deg, duration = 10000) {
  deg = Math.round(deg);
  $("img.roulette").animate(
      { now: '+='+(720+deg-getRotation()) }, {
      duration: duration,
      ...
      step: function(now, fx) {
        if(now >= 360)
          now -= 360;
        $(this).css("transform", "rotate("+now+"deg)");
      }
    });
}

如果持续时间少于10秒,动画的开始时间为隔断。因此,如果服务器在大约5秒钟前旋转了轮子,则应该删除动画的前5秒钟。

If the duration would be less then 10 seconds the start of the animation would be cut off. So, if the server spun the wheel about 5 seconds ago the first 5 seconds of my animation should be cut off.

推荐答案

捕获在任何时间点上进行动画缓动旋转



查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆