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),
$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) {

Loading…
Cancel
Save