From 187e68f9a28fb73418978501c07349880a33c701 Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 28 Apr 2015 15:29:38 -0400 Subject: [PATCH] Increase sticky performance with scroll --- src/definitions/modules/sticky.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index 40d2e7702..e965db79c 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -210,6 +210,9 @@ $.fn.sticky = function(parameters) { lastScroll: function(scroll) { module.lastScroll = scroll; }, + elementScroll: function(scroll) { + module.elementScroll = scroll; + }, positions: function() { var window = { @@ -281,6 +284,9 @@ $.fn.sticky = function(parameters) { ; }, currentElementScroll: function() { + if(module.elementScroll) { + return module.elementScroll; + } return ( module.is.top() ) ? Math.abs(parseInt($module.css('top'), 10)) || 0 : Math.abs(parseInt($module.css('bottom'), 10)) || 0 @@ -295,8 +301,7 @@ $.fn.sticky = function(parameters) { delta = module.get.scrollChange(scroll), maxScroll = (element.height - window.height + settings.offset), elementScroll = module.get.currentElementScroll(), - possibleScroll = (elementScroll + delta), - elementScroll + possibleScroll = (elementScroll + delta) ; if(module.cache.fits || possibleScroll < 0) { elementScroll = 0; @@ -415,6 +420,7 @@ $.fn.sticky = function(parameters) { // save current scroll for next run module.save.lastScroll(scroll.top); + module.save.elementScroll(elementScroll); if(elementVisible) {