From 6073367a3c53a9c13381e9a91b65a6fa334ad2d2 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 1 Nov 2015 12:59:28 -0500 Subject: [PATCH] Fixes bug where sticky would stick at incorrect times when using a different scroll container than and when the container's is not 0 on init. --- src/definitions/modules/sticky.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index f37d1bea8..1ca2677c5 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -236,16 +236,28 @@ $.fn.sticky = function(parameters) { height : $module.outerHeight() }, context = { - offset : $context.offset(), - height : $context.outerHeight() + offset : $context.offset(), + height : $context.outerHeight() }, container = { height: $container.outerHeight() - } + }, + scroll ; + if(!module.is.standardScroll()) { + module.debug('Non-standard scroll. Removing scroll offset from element offset'); + scroll = { + top : $scroll.scrollTop(), + left : $scroll.scrollLeft() + } + element.offset.top += scroll.top; + context.offset.top += scroll.top; + element.offset.left += scroll.left; + context.offset.left += scroll.left; + } module.cache = { fits : ( element.height < window.height ), - window: { + window : { height: window.height }, element: { @@ -397,6 +409,9 @@ $.fn.sticky = function(parameters) { }, is: { + standardScroll: function() { + return ($scroll[0] == window); + }, top: function() { return $module.hasClass(className.top); }, @@ -884,4 +899,4 @@ $.fn.sticky.settings = { }; -})( jQuery, window , document ); +})( jQuery, window, document ); \ No newline at end of file