diff --git a/src/jquery.stellar.js b/src/jquery.stellar.js index 98b2ea5..ae10306 100644 --- a/src/jquery.stellar.js +++ b/src/jquery.stellar.js @@ -504,32 +504,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 +588,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 +652,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));