Browse Source

Prevent sticky from calling .offsetParent() on every method call by finding container only in init

dimmer-flex
jlukic 9 years ago
parent
commit
923e3d40cf
1 changed files with 8 additions and 3 deletions
  1. 11
      src/definitions/modules/sticky.js

11
src/definitions/modules/sticky.js

@ -43,8 +43,8 @@ $.fn.sticky = function(parameters) {
$module = $(this), $module = $(this),
$window = $(window), $window = $(window),
$container = $module.offsetParent(),
$scroll = $(settings.scrollContext), $scroll = $(settings.scrollContext),
$container,
$context, $context,
selector = $module.selector || '', selector = $module.selector || '',
@ -65,6 +65,7 @@ $.fn.sticky = function(parameters) {
initialize: function() { initialize: function() {
module.determineContainer();
module.determineContext(); module.determineContext();
module.verbose('Initializing sticky', settings, $container); module.verbose('Initializing sticky', settings, $container);
@ -126,6 +127,10 @@ $.fn.sticky = function(parameters) {
} }
}, },
determineContainer: function() {
$container = $module.offsetParent();
},
determineContext: function() { determineContext: function() {
if(settings.context) { if(settings.context) {
$context = $(settings.context); $context = $(settings.context);
@ -191,7 +196,7 @@ $.fn.sticky = function(parameters) {
module.determineContext(); module.determineContext();
} }
if(hardRefresh) { if(hardRefresh) {
$container = $module.offsetParent();
module.determineContainer();
} }
module.save.positions(); module.save.positions();
module.stick(); module.stick();
@ -337,7 +342,7 @@ $.fn.sticky = function(parameters) {
if(tagName === 'HTML' || tagName == 'body') { if(tagName === 'HTML' || tagName == 'body') {
// this can trigger for too many reasons // this can trigger for too many reasons
//module.error(error.container, tagName, $module); //module.error(error.container, tagName, $module);
$container = $module.offsetParent();
module.determineContainer();
} }
else { else {
if( Math.abs($container.height() - module.cache.context.height) > 5) { if( Math.abs($container.height() - module.cache.context.height) > 5) {

Loading…
Cancel
Save