From 923e3d40cf0318df2402cec0494ec3e944c31725 Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 2 Jun 2015 19:02:20 -0400 Subject: [PATCH] Prevent sticky from calling .offsetParent() on every method call by finding container only in init --- src/definitions/modules/sticky.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index abd884925..de00a4c60 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -43,8 +43,8 @@ $.fn.sticky = function(parameters) { $module = $(this), $window = $(window), - $container = $module.offsetParent(), $scroll = $(settings.scrollContext), + $container, $context, selector = $module.selector || '', @@ -65,6 +65,7 @@ $.fn.sticky = function(parameters) { initialize: function() { + module.determineContainer(); module.determineContext(); module.verbose('Initializing sticky', settings, $container); @@ -126,6 +127,10 @@ $.fn.sticky = function(parameters) { } }, + determineContainer: function() { + $container = $module.offsetParent(); + }, + determineContext: function() { if(settings.context) { $context = $(settings.context); @@ -191,7 +196,7 @@ $.fn.sticky = function(parameters) { module.determineContext(); } if(hardRefresh) { - $container = $module.offsetParent(); + module.determineContainer(); } module.save.positions(); module.stick(); @@ -337,7 +342,7 @@ $.fn.sticky = function(parameters) { if(tagName === 'HTML' || tagName == 'body') { // this can trigger for too many reasons //module.error(error.container, tagName, $module); - $container = $module.offsetParent(); + module.determineContainer(); } else { if( Math.abs($container.height() - module.cache.context.height) > 5) {