|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | ;(function ( $, window, document, undefined ) {
|
8 |
| - |
9 |
| - // Polyfill for requestAnimationFrame |
10 |
| - // via: https://gist.github.com/paulirish/1579671 |
11 |
| - |
12 |
| - (function() { |
13 |
| - var lastTime = 0; |
14 |
| - var vendors = ['ms', 'moz', 'webkit', 'o']; |
15 |
| - for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { |
16 |
| - window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; |
17 |
| - window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; |
18 |
| - } |
19 |
| - |
20 |
| - if (!window.requestAnimationFrame) |
21 |
| - window.requestAnimationFrame = function(callback) { |
22 |
| - var currTime = new Date().getTime(); |
23 |
| - var timeToCall = Math.max(0, 16 - (currTime - lastTime)); |
24 |
| - var id = window.setTimeout(function() { callback(currTime + timeToCall); }, |
25 |
| - timeToCall); |
26 |
| - lastTime = currTime + timeToCall; |
27 |
| - return id; |
28 |
| - }; |
29 |
| - |
30 |
| - if (!window.cancelAnimationFrame) |
31 |
| - window.cancelAnimationFrame = function(id) { |
32 |
| - clearTimeout(id); |
33 |
| - }; |
34 |
| - }()); |
35 |
| - |
36 |
| - |
37 | 8 | // Parallax Constructor
|
38 | 9 |
|
39 | 10 | function Parallax(element, options) {
|
|
267 | 238 | setup: function() {
|
268 | 239 | if (this.isReady) return;
|
269 | 240 |
|
270 |
| - this.lastRequestAnimationFrame = null; |
| 241 | + var self = this; |
271 | 242 |
|
272 | 243 | var $doc = $(document), $win = $(window);
|
273 | 244 |
|
|
289 | 260 |
|
290 | 261 | $win.on('resize.px.parallax load.px.parallax', function() {
|
291 | 262 | loadDimensions();
|
| 263 | + self.refresh(); |
292 | 264 | Parallax.isFresh = false;
|
293 | 265 | Parallax.requestRender();
|
294 | 266 | })
|
|
323 | 295 |
|
324 | 296 | requestRender: function() {
|
325 | 297 | var self = this;
|
326 |
| - window.cancelAnimationFrame(self.lastRequestAnimationFrame); |
327 | 298 |
|
328 |
| - self.lastRequestAnimationFrame = window.requestAnimationFrame(function() { |
329 |
| - self.render(); |
330 |
| - self.isBusy = false; |
331 |
| - }); |
| 299 | + self.render(); |
| 300 | + self.isBusy = false; |
332 | 301 | },
|
333 | 302 | destroy: function(el){
|
334 | 303 | var i,
|
|
0 commit comments