From c42b2a1a692e2e87cb581b176e5c809090e9ad85 Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 1 Jul 2014 08:30:50 +0200 Subject: [PATCH 1/2] moved scroll checks from requestAnimFrame to onscroll, improves performance --- src/jquery.stellar.js | 71 +++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/src/jquery.stellar.js b/src/jquery.stellar.js index 98b2ea5..17a2bf3 100644 --- a/src/jquery.stellar.js +++ b/src/jquery.stellar.js @@ -1,3 +1,12 @@ +/*! + * Stellar.js v0.6.2 + * http://markdalgleish.com/projects/stellar.js + * + * Copyright 2014, Mark Dalgleish + * This content is released under the MIT license + * http://markdalgleish.mit-license.org + */ + ;(function($, window, document, undefined) { var pluginName = 'stellar', @@ -504,32 +513,25 @@ } }, _repositionElements: function() { - var scrollLeft = this._getScrollLeft(), - scrollTop = this._getScrollTop(), - horizontalOffset, - verticalOffset, - particle, - fixedRatioOffset, - background, - bgLeft, - bgTop, - isVisibleVertical = true, - isVisibleHorizontal = true, - newPositionLeft, - newPositionTop, - newOffsetLeft, - newOffsetTop, - i; - - // First check that the scroll position or container size has changed - if (this.currentScrollLeft === scrollLeft && this.currentScrollTop === scrollTop && this.currentWidth === this.viewportWidth && this.currentHeight === this.viewportHeight) { - return; - } else { - this.currentScrollLeft = scrollLeft; - this.currentScrollTop = scrollTop; - this.currentWidth = this.viewportWidth; - this.currentHeight = this.viewportHeight; - } + var scrollLeft=this.currentScrollLeft, + scrollTop=this.currentScrollTop, + horizontalOffset, + verticalOffset, + particle, + fixedRatioOffset, + background, + bgLeft, + bgTop, + isVisibleVertical = true, + isVisibleHorizontal = true, + newPositionLeft, + newPositionTop, + newOffsetLeft, + newOffsetTop, + i; + + this.currentWidth = this.viewportWidth; + this.currentHeight = this.viewportHeight; // Reposition elements for (i = this.particles.length - 1; i >= 0; i--) { @@ -595,8 +597,19 @@ ticking = false; }; - var requestTick = function() { - if (!ticking) { + var requestTick = function(evt) { + var scrollLeft = self._getScrollLeft(); + var scrollTop = self._getScrollTop(); + + // First check that the scroll position or container size has changed + if (((self.currentScrollLeft === scrollLeft && self.currentWidth === self.viewportWidth) || !self.options.horizontalScrolling) && ((self.currentScrollTop === scrollTop && self.currentHeight === self.viewportHeight) || !self.options.verticalScrolling)) { + return; + } + + self.currentScrollLeft = scrollLeft; + self.currentScrollTop = scrollTop; + + if (!ticking) { requestAnimFrame(update); ticking = true; } @@ -648,4 +661,4 @@ // Expose the plugin class so it can be modified window.Stellar = Plugin; -}(jQuery, this, document)); \ No newline at end of file +}(jQuery, this, document)); From 63f870471ccddae7ba17c810b27bd1a7743835d5 Mon Sep 17 00:00:00 2001 From: Remco Date: Tue, 1 Jul 2014 08:33:14 +0200 Subject: [PATCH 2/2] moved scroll checks from requestAnimFrame to onscroll, improves performance --- src/jquery.stellar.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/jquery.stellar.js b/src/jquery.stellar.js index 17a2bf3..ae10306 100644 --- a/src/jquery.stellar.js +++ b/src/jquery.stellar.js @@ -1,12 +1,3 @@ -/*! - * Stellar.js v0.6.2 - * http://markdalgleish.com/projects/stellar.js - * - * Copyright 2014, Mark Dalgleish - * This content is released under the MIT license - * http://markdalgleish.mit-license.org - */ - ;(function($, window, document, undefined) { var pluginName = 'stellar',