2015-12-17 169 views
13

我試圖讓一個齒輪圍繞其z軸旋轉。它按預期工作,但是在5000次持續時間後纔會逆轉。我該如何阻止它倒退,只讓它前進?Velocity.js圍繞中心軸旋轉

感謝

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

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

有沒有人有任何想法? –

回答

8

這是速度的已知的bug和朱利安說,他將被修復,但沒有,據我所知,沒有已知的發佈日期:

https://github.com/julianshapiro/velocity/issues/453(旋轉負值旋轉以順時針方向返回)

因爲順時針方向的循環確實有效,所以在逆時針方向上進行無限循環的快速工作就像這樣,直到錯誤得到修復:

小提琴: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}); 
} 

這裏是加快多一點複雜的例子,放慢速度d儘管在邊緣上有些粗糙,但總體思路在那裏。

小提琴:https://jsfiddle.net/AtheistP3ace/znyLtfaf/4/

+0

嗨,無神論者,謝謝你的幫助!我嘗試了小提琴,它什麼都不做?即使按下「開始」按鈕? –

+0

哎呀,它不喜歡我包括速度的方式。我修復它一秒。 – AtheistP3ace

+0

OK @CamrinParnell嘗試新的小提琴鏈接。 – AtheistP3ace