最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Velocity.js Rotation Around Center Axis - Stack Overflow

programmeradmin0浏览0评论

I'm trying to make a gear rotate around its z axis. It works as expected, but then reverses after the 5000 duration. How do I stop it from reversing and only make it go forward?

Thanks

var gear_width = $('.gear').width();
var gear_height = $('.gear').height();

$('.gear').velocity({  rotateZ:-360 }, { duration: 5000, easing: "linear", loop: true,});

I'm trying to make a gear rotate around its z axis. It works as expected, but then reverses after the 5000 duration. How do I stop it from reversing and only make it go forward?

Thanks

var gear_width = $('.gear').width();
var gear_height = $('.gear').height();

$('.gear').velocity({  rotateZ:-360 }, { duration: 5000, easing: "linear", loop: true,});
Share Improve this question asked Dec 17, 2015 at 0:45 Camrin ParnellCamrin Parnell 4492 gold badges9 silver badges21 bronze badges 1
  • Does anyone have any ideas? – Camrin Parnell Commented Dec 19, 2015 at 2:24
Add a ment  | 

1 Answer 1

Reset to default 8 +25

This is a known bug in Velocity and Julian says he will be fixing it but there is no known release date as far as I know:

https://github./julianshapiro/velocity/issues/453 (Rotate negative value rotates back in clockwise)

Since looping in the clockwise direction does indeed work, a quick work around to get infinite looping in the counterclockwise direction is something like this until the bug is fixed:

Fiddle: https://jsfiddle/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", plete: loopMeLeft});
}

And here is a bit more plicated example with speeding up and slowing down the gears dynamically albeit a bit rough around the edges but the general idea is there.

Fiddle: https://jsfiddle/AtheistP3ace/znyLtfaf/4/

发布评论

评论列表(0)

  1. 暂无评论