|
146 | 146 | parts[indexOfNthMatch] = replace;
|
147 | 147 |
|
148 | 148 | return parts.join('');
|
149 |
| - }; |
| 149 | + }, |
| 150 | + |
| 151 | + requestAnimFrame = (function(){ |
| 152 | + return window.requestAnimationFrame || |
| 153 | + window.webkitRequestAnimationFrame || |
| 154 | + window.mozRequestAnimationFrame || |
| 155 | + window.oRequestAnimationFrame || |
| 156 | + window.msRequestAnimationFrame || |
| 157 | + function(callback, element){ |
| 158 | + window.setTimeout(callback, 1000 / 60); |
| 159 | + }; |
| 160 | + }()); |
150 | 161 |
|
151 | 162 | function Plugin(element, options) {
|
152 | 163 | this.element = element;
|
|
600 | 611 | }
|
601 | 612 | },
|
602 | 613 | _handleScrollEvent: function() {
|
603 |
| - this.$scrollElement.bind('scroll.' + this.name, $.proxy(this._repositionElements, this)); |
604 |
| - this._repositionElements(); |
| 614 | + var self = this, |
| 615 | + ticking = false; |
| 616 | + |
| 617 | + var update = function() { |
| 618 | + self._repositionElements(); |
| 619 | + ticking = false; |
| 620 | + }; |
| 621 | + |
| 622 | + var requestTick = function() { |
| 623 | + if (!ticking) { |
| 624 | + requestAnimFrame(update); |
| 625 | + ticking = true; |
| 626 | + } |
| 627 | + }; |
| 628 | + |
| 629 | + this.$scrollElement.bind('scroll.' + this.name, requestTick); |
| 630 | + update(); |
605 | 631 | },
|
606 | 632 | _startAnimationLoop: function() {
|
607 |
| - var self = this, |
608 |
| - requestAnimFrame = (function(){ |
609 |
| - return window.requestAnimationFrame || |
610 |
| - window.webkitRequestAnimationFrame || |
611 |
| - window.mozRequestAnimationFrame || |
612 |
| - window.oRequestAnimationFrame || |
613 |
| - window.msRequestAnimationFrame || |
614 |
| - function(callback, element){ |
615 |
| - window.setTimeout(callback, 1000 / 60); |
616 |
| - }; |
617 |
| - }()); |
| 633 | + var self = this; |
618 | 634 |
|
619 | 635 | this._animationLoop = function(){
|
620 | 636 | requestAnimFrame(self._animationLoop);
|
|
0 commit comments