Browse Source

Increase sticky performance with scroll

pull/2158/merge
jlukic 9 years ago
parent
commit
187e68f9a2
1 changed files with 8 additions and 2 deletions
  1. 10
      src/definitions/modules/sticky.js

10
src/definitions/modules/sticky.js

@ -210,6 +210,9 @@ $.fn.sticky = function(parameters) {
lastScroll: function(scroll) { lastScroll: function(scroll) {
module.lastScroll = scroll; module.lastScroll = scroll;
}, },
elementScroll: function(scroll) {
module.elementScroll = scroll;
},
positions: function() { positions: function() {
var var
window = { window = {
@ -281,6 +284,9 @@ $.fn.sticky = function(parameters) {
; ;
}, },
currentElementScroll: function() { currentElementScroll: function() {
if(module.elementScroll) {
return module.elementScroll;
}
return ( module.is.top() ) return ( module.is.top() )
? Math.abs(parseInt($module.css('top'), 10)) || 0 ? Math.abs(parseInt($module.css('top'), 10)) || 0
: Math.abs(parseInt($module.css('bottom'), 10)) || 0 : Math.abs(parseInt($module.css('bottom'), 10)) || 0
@ -295,8 +301,7 @@ $.fn.sticky = function(parameters) {
delta = module.get.scrollChange(scroll), delta = module.get.scrollChange(scroll),
maxScroll = (element.height - window.height + settings.offset), maxScroll = (element.height - window.height + settings.offset),
elementScroll = module.get.currentElementScroll(), elementScroll = module.get.currentElementScroll(),
possibleScroll = (elementScroll + delta),
elementScroll
possibleScroll = (elementScroll + delta)
; ;
if(module.cache.fits || possibleScroll < 0) { if(module.cache.fits || possibleScroll < 0) {
elementScroll = 0; elementScroll = 0;
@ -415,6 +420,7 @@ $.fn.sticky = function(parameters) {
// save current scroll for next run // save current scroll for next run
module.save.lastScroll(scroll.top); module.save.lastScroll(scroll.top);
module.save.elementScroll(elementScroll);
if(elementVisible) { if(elementVisible) {

Loading…
Cancel
Save