【问题标题】:stop jQueryRotate plugin on mouseover on current position and continue on mouseout在当前位置鼠标悬停时停止 jQueryRotate 插件并在鼠标悬停时继续
【发布时间】:2012-07-27 15:30:28
【问题描述】:

我正在尝试使用 jQueryRotate 插件在鼠标悬停的当前位置停止旋转轮,并在鼠标移出时继续动画旋转,

我似乎无法使其与适用于我的自定义动画的 stop 方法一起工作

纺车的代码在jsfiddle

var angle = 0;
    setInterval(function(){
        angle+=3;
    $("#carwheel").rotate(angle,{ easing:'easeInOutElastic'});

    $("#carwheel")
    .mouseover(function () { $(this).stop(); })
    .mouseout(function () { $(this).resume(); })

    },100);

【问题讨论】:

    标签: jquery animation rotation mouseover mouseout


    【解决方案1】:

    以下代码将为您工作,

    var angle = 0;
    var int;
    rotateImage();
    
    function rotateImage() {
        int = setInterval(function() {
            angle += 3;
            $("#image").rotate(angle);
        }, 50);
    }
    $("#image").mouseover(function() {
        clearInterval(int);
        //$(this).stop();
    }).mouseout(function() {
        rotateImage();
    });​
    

    http://jsfiddle.net/73pXD/2393/

    【讨论】:

    • 感谢工作的人你能解释一下你做了什么 clearInterval 是什么
    • clearInterval 清除使用setInterval 设置的间隔。要做到这一点,区间变量应该是全局的。 setInterval 定期调用任何函数,clearInterval 将停止它。
    • @Marcos:嗯,不接受,赞成票只是说有效。你认为人们会不再回答你未来的问题吗?
    • Sandmal 谢谢伙计,很抱歉,自从我在这里登录以来已经有一段时间没有回复了,我以为我已经说了谢谢,但我想我没有写我想象的那样,但是谢谢伙计,会的下次说声谢谢,如果你想看清楚间隔做了什么,你可以查看这个例子modifiedarts.com
    猜你喜欢
    • 1970-01-01
    • 2012-05-04
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多