0

超大規模な jquery プラグイン ( here ) で下部 ( from here )のコードを使用しようとしています。これは、画像と音声を同期させているため、より正確なタイマーが必要だからです。

基本的に、スーパーサイズには次の行があります。

vars.slideshow_interval = setInterval(base.nextSlide, base.options.slide_interval);

clearInterval(vars.slideshow_interval); 

私は次のようなことをする必要があります:

vars.slideshow_interval = accurateInterval(base.nextSlide, base.options.slide_interval);

vars.slideshow_interval.clear();

私のjavascriptスキルが多少制限されており、以下の関数の用語/説明さえ知らない問題。問題は、間違ったコンテキストで (this) を使用することと関係があると思われるためです。

コードをそのまま使用しようとしましたが、clear() を呼び出すと、「関数エラーではありません」というメッセージが表示されます。

どうすればこれを機能させることができますか?任意のポインタ、大歓迎です。ありがとうございました。

(function () {
    window.accurateInterval = function (time, fn) {
        var cancel, nextAt, timeout, wrapper, _ref;
        nextAt = new Date().getTime() + time;
        timeout = null;
        if (typeof time === 'function') _ref = [time, fn], fn = _ref[0], time = _ref[1];
        wrapper = function () {
            nextAt += time;
            timeout = setTimeout(wrapper, nextAt - new Date().getTime());
            return fn();
        };

        cancel = function () {
            return clearTimeout(timeout);
        };

        timeout = setTimeout(wrapper, nextAt - new Date().getTime());
        return {
            cancel: cancel
        };
    };
}).call(this);
4

1 に答える 1

0
于 2013-01-20T13:44:31.217 に答える