首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery图像旋转跟踪正弦波角

问jQuery图像旋转跟踪正弦波角
EN

Stack Overflow用户
提问于 2013-11-04 23:23:58
回答 1查看 762关注 0票数 2

解决了-

我正试图动画一个图像,以旋转的角度,一个正弦波-正弦波是创建使用jQuery.path插件。

问题是如何使旋转平稳。

我目前正在使用的jQuery旋转插件的旋转,这-它目前的立场-并不是创造一个平稳的旋转。

参见http://hellosmithers.com/GNU/STALLMANQUEST.html中的JavaScript和jQuery。

该脚本的注释相对较多。

目前,旋转只是重复和花费一定的时间来完成-这意味着它不会工作的所有屏幕大小,因为正弦波需要更长的时间来完成屏幕越宽。

代码语言:javascript
复制
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
}

正弦波产生如下:

代码语言:javascript
复制
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"};
    }
}

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-05 04:37:05

我想出来了-这个角度来自p,我用过(p * 12) -

代码语言:javascript
复制
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 -

代码语言:javascript
复制
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
    });
}

确保声明数组变量-

代码语言:javascript
复制
rA = new Array (-8, 8);
prA = rA[1] = [rA[0], rA[0] = rA[1]][0];

如果您想查看完整的代码,请访问http://hellosmithers.com/GNU/STALLMANQUEST.html。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19779207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档