1

setInterval の機能が動作している間に速度を変更する方法がわかりません..

コード内:

var timeout, count = 0, speed = 5000;

                  $('#stage').mousedown(function() {
                    timeout = setInterval(function() {
                        speed = parseInt(speed / 1.3); // HERE I want change speed
                        create(speed); // Some Function
                    }, speed); // This speed, I don't know how to change
                });

                $('#stage').mouseup(function() {
                    count = 0;
                    clearInterval(timeout);
                });

これは機能しますが、速度は関数外です const (5000)

すべての助けに感謝します!

4

2 に答える 2

1

新しい setTimeout 関数に渡すには、名前付き関数を使用する必要があります。

var speed = 5000;
var timer;

$('#stage').mousedown(function() {
    timer = setTimeout(handleTick, speed);
});

$('#stage').mouseup(function() {
    clearTimeout(timer);    
});

var handleTick = function () {
    speed = parseInt(speed / 1.3);
    timer = setTimeout(handleTick, speed);
};
于 2013-09-22T13:33:15.353 に答える