Javascript jQuery图像旋转以跟随正弦波的角度 解决-
我正在尝试设置图像动画,使其沿着正弦波的角度旋转-正弦波是使用jQuery.path插件创建的 问题在于如何获得平滑的旋转 我目前正在使用jQueryRotate插件进行旋转,目前的情况是,它并没有创建平滑的旋转 有关JavaScript和jQuery,请参阅 该脚本的评论相对较多 目前,旋转只是重复,并需要一定的时间来完成-这意味着它不会适用于所有屏幕大小,因为正弦波需要更长的时间来完成更宽的屏幕Javascript jQuery图像旋转以跟随正弦波的角度 解决-,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我正在尝试设置图像动画,使其沿着正弦波的角度旋转-正弦波是使用jQuery.path插件创建的 问题在于如何获得平滑的旋转 我目前正在使用jQueryRotate插件进行旋转,目前的情况是,它并没有创建平滑的旋转 有关JavaScript和jQuery,请参阅 该脚本的评论相对较多 目前,旋转只是重复,并需要一定的时间来完成-这意味着它不会适用于所有屏幕大小,因为正弦波需要更长的时间来完成更宽的屏幕 function mRot() { // image rotation - it goes fr
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"};
}
}
谢谢我算出来了-角度是从p导出的,我用了(p*12)- 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
});
}
如果您想查看完整的代码,请访问,您可能希望在问题中提供有关您的问题的更多详细信息,而不是链接到某个页面并期望有人深入了解您的源代码。也许可以将问题归结为一些小的示例代码片段,并将其包含在您的问题中。谢谢Fraser,完成了。很高兴提供任何澄清。
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];