function Animator(duration, progress) {
    this.duration = duration;
    this.progress = progress;
    this.next = true;
}
Animator.prototype = {
    constructor: Animator,
    start: function (finished) {
        var startTime = new Date().getTime();
        var duration = this.duration,
            self = this,
            timeOut = 0;
        var vendors = ['webkit', 'moz'];
        for (var i = 0; i < vendors.length && !window.requestAnimationFrame; ++i) {
            window.requestAnimationFrame = window[vendors[i] + 'RequestAnimationFrame'];
        }
        if (!window.requestAnimationFrame) {
            window.requestAnimationFrame = function (callback, element) {
                var start = 0,
                    finish = 0;
                window.setTimeout(function () {
                    start = +new Date();
                    callback(start);
                    finish = +new Date();
                    timeOut = 1000 / 300 - (finish - start);
                }, timeOut);
            };
        }

        window.requestAnimationFrame(function step() {
            var p = (new Date().getTime() - startTime) / duration;
            self.progress(p, p);
            if (p >= 1.0) {
                self.progress(1.0, 1.0);
                self.next = false;
                finished();
            }

            if (self.next) {
                window.requestAnimationFrame(step);
            }

        });
    },
    stop: function () {
        this.next = false;
    }
};


相关文章:

  • 2021-11-13
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2021-09-19
  • 2021-10-25
  • 2022-12-23
猜你喜欢
  • 2021-11-16
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-23
相关资源
相似解决方案