JQuery .stopRotate 不工作

JQuery .stopRotate not working

我正在开展一个项目,为我的工作创建一个命运之轮类型的网站。我已经成功地让一个 PNG 轮子连续旋转,但是我无法让它在单击按钮时停止。我试过clearInterval(interval),我也试过.stopRotate()。没有任何效果!这越来越令人沮丧。任何帮助将不胜感激!

这是我的 JQuery 代码:

    var angle = 1;      //Set angle to move in 1 degree increments
    $(document).ready(function () {
        $("#spin").click(function () {
     setInterval(function () {
            angle += 5;         //keep angle increments at 5 degrees to keep moving
                $("#wheel").rotate(angle);
            });
        });
        $("#stop").click(function () {
            $("#wheel").stopRotate();
        });
    });

是的,您没有停止 setInterval 的旋转功能。您需要在 javascript

中使用 clearInterval 清除 setInterval
var angle = 1;      //Set angle to move in 1 degree increments
var timer;
    $(document).ready(function () {
        $("#spin").click(function () {
               timer = setInterval(function () {
                       angle += 5;         //keep angle increments at 5 degrees to keep moving
                $("#wheel").rotate(angle);
              });
        });
        $("#stop").click(function () {
            clearInterval(timer);
        });
    });