我试图使一个齿轮绕其z轴旋转。它的表现如预期一样,但在5000的时间后会反向旋转。我该如何阻止它反向旋转,只让它朝一个方向旋转?
谢谢。
var gear_width = $('.gear').width();
var gear_height = $('.gear').height();
$('.gear').velocity({ rotateZ:-360 }, { duration: 5000, easing: "linear", loop: true,});
我试图使一个齿轮绕其z轴旋转。它的表现如预期一样,但在5000的时间后会反向旋转。我该如何阻止它反向旋转,只让它朝一个方向旋转?
谢谢。
var gear_width = $('.gear').width();
var gear_height = $('.gear').height();
$('.gear').velocity({ rotateZ:-360 }, { duration: 5000, easing: "linear", loop: true,});
这是Velocity中已知的一个问题,Julian表示他将修复它,但据我所知没有已知的发布日期:
https://github.com/julianshapiro/velocity/issues/453(负值旋转会顺时针旋转回来)
由于以顺时针方向循环确实有效,因此在解决该问题之前,在逆时针方向进行无限循环的快速解决方法如下:
Fiddle:https://jsfiddle.net/znyLtfaf/2/
HTML:
<div class="gear gearRight">rotate right</div>
<div class="gear gearLeft">rotate left</div>
CSS:
.gear {
width: 100px;
height: 100px;
position: absolute;
background: red;
}
.gearRight {
top: 100px;
left: 100px;
}
.gearLeft {
top: 300px;
left: 100px;
}
JS:
$('.gearRight').velocity({ rotateZ: "+=360" }, { duration: 5000, easing: "linear", loop: true});
loopMeLeft();
function loopMeLeft () {
$('.gearLeft').velocity({ rotateZ: "-=360" }, { duration: 5000, easing: "linear", complete: loopMeLeft});
}
这里有一个更复杂的例子,可以动态加速和减速齿轮,虽然还有一些问题需要解决,但大致思路已经出来了。