解决了-
我正试图动画一个图像,以旋转的角度,一个正弦波-正弦波是创建使用jQuery.path插件。
问题是如何使旋转平稳。
我目前正在使用的jQuery旋转插件的旋转,这-它目前的立场-并不是创造一个平稳的旋转。
参见http://hellosmithers.com/GNU/STALLMANQUEST.html中的JavaScript和jQuery。
该脚本的注释相对较多。
目前,旋转只是重复和花费一定的时间来完成-这意味着它不会工作的所有屏幕大小,因为正弦波需要更长的时间来完成屏幕越宽。
function mRot() { // image rotation - it goes from rA[0] (-8 degrees) to rA[1] (8 degrees) then swaps the values
// flip the values in rA - making the rotation oposite each iteration of this funciton
rA[1] = [rA[0], rA[0] = rA[1]][0];
$("#rmat").rotate({
duration: 1700,
angle: rA[0],
animateTo: rA[1],
callback: mRot
}); // I would like to remove this function - instead tying the rotation into the sine wave function somehow
}正弦波产生如下:
SineWave = function() { // create the sine wave - as per https://github.com/weepy/jquery.path
this.css = function(p) {
s = Math.sin(p * 12);
x = winWidth - p * (winWidth + 250);
y = s * 40 + (winHeight - 440);
return {top: y + "px", left: x + "px"};
}
}谢谢
发布于 2013-11-05 04:37:05
我想出来了-这个角度来自p,我用过(p * 12) -
SineWave = function() {
this.css = function(p) {
rA[0] = p * 12; // get the angle
s = Math.sin(p * 12);
x = winWidth - p * (winWidth + 250);
y = s * 40 + (winHeight - 440);
return {top: y + "px", left: x + "px"};
}
}函数mRot使用rA -
function mRot() {
rA[0] = prA[1]; // rA[0] will always be the previous rA[1]
if (prA[1] < 0) rA[1] = Math.abs(rA[1]); // if the previous rA[1] is a negative number, make the current rA positive.
else rA[1] = -(rA[1]); // otherwise make it negative
prA = rA;
$("#rmat").rotate({
duration: 1500,
angle: rA[0],
animateTo: rA[1],
callback: mRot
});
}确保声明数组变量-
rA = new Array (-8, 8);
prA = rA[1] = [rA[0], rA[0] = rA[1]][0];如果您想查看完整的代码,请访问http://hellosmithers.com/GNU/STALLMANQUEST.html。
https://stackoverflow.com/questions/19779207
复制相似问题