diff --git a/src/definitions/behaviors/visibility.js b/src/definitions/behaviors/visibility.js index 586ac3ddc..f931e6ab7 100644 --- a/src/definitions/behaviors/visibility.js +++ b/src/definitions/behaviors/visibility.js @@ -52,6 +52,7 @@ $.fn.visibility = function(parameters) { || function(callback) { setTimeout(callback, 0); }, element = this, + observer, module ; @@ -73,6 +74,9 @@ $.fn.visibility = function(parameters) { } } module.checkVisibility(); + if(settings.observeChanges) { + module.observeChanges(); + } module.instantiate(); }, @@ -92,6 +96,26 @@ $.fn.visibility = function(parameters) { ; }, + observeChanges: function() { + var + context = $context[0] + ; + if('MutationObserver' in window) { + observer = new MutationObserver(function(mutations) { + clearTimeout(module.timer); + module.timer = setTimeout(function() { + module.verbose('DOM tree modified, updating visibility calculations'); + module.refresh(); + }, 20); + }); + observer.observe(element, { + childList : true, + subtree : true + }); + module.debug('Setting up mutation observer', observer); + } + }, + bindEvents: function() { module.verbose('Binding visibility events to scroll and resize'); $window @@ -236,6 +260,15 @@ $.fn.visibility = function(parameters) { } }, + is: { + visible: function() { + if(module.cache && module.cache.element) { + return (module.cache.element.height > 0 && module.cache.element.width > 0); + } + return false; + } + }, + refresh: function() { module.debug('Refreshing constants (element width/height)'); module.reset(); @@ -256,22 +289,24 @@ $.fn.visibility = function(parameters) { module.verbose('Checking visibility of element', module.cache.element); module.save.calculations(); - // percentage - module.passed(); + if( module.is.visible() ) { + // percentage + module.passed(); - // reverse (must be first) - module.passingReverse(); - module.topVisibleReverse(); - module.bottomVisibleReverse(); - module.topPassedReverse(); - module.bottomPassedReverse(); + // reverse (must be first) + module.passingReverse(); + module.topVisibleReverse(); + module.bottomVisibleReverse(); + module.topPassedReverse(); + module.bottomPassedReverse(); - // one time - module.passing(); - module.topVisible(); - module.bottomVisible(); - module.topPassed(); - module.bottomPassed(); + // one time + module.passing(); + module.topVisible(); + module.bottomVisible(); + module.topPassed(); + module.bottomPassed(); + } }, passed: function(amount, newCallback) { @@ -918,6 +953,8 @@ $.fn.visibility.settings = { fixed: 'fixed' }, + observeChanges : true, + debug : false, verbose : false, performance : true, diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index 6354f90a4..78d6ba19c 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -91,8 +91,9 @@ $.fn.sticky = function(parameters) { $scroll .on('scroll' + eventNamespace, module.event.scroll) ; - - module.observeChanges(); + if(settings.observeChanges) { + module.observeChanges(); + } module.instantiate(); }, @@ -125,25 +126,23 @@ $.fn.sticky = function(parameters) { var context = $context[0] ; - if(settings.observeChanges) { - if('MutationObserver' in window) { - observer = new MutationObserver(function(mutations) { - clearTimeout(module.timer); - module.timer = setTimeout(function() { - module.verbose('DOM tree modified, updating sticky menu'); - module.refresh(); - }, 200); - }); - observer.observe(element, { - childList : true, - subtree : true - }); - observer.observe(context, { - childList : true, - subtree : true - }); - module.debug('Setting up mutation observer', observer); - } + if('MutationObserver' in window) { + observer = new MutationObserver(function(mutations) { + clearTimeout(module.timer); + module.timer = setTimeout(function() { + module.verbose('DOM tree modified, updating sticky menu'); + module.refresh(); + }, 20); + }); + observer.observe(element, { + childList : true, + subtree : true + }); + observer.observe(context, { + childList : true, + subtree : true + }); + module.debug('Setting up mutation observer', observer); } }, diff --git a/src/definitions/modules/transition.js b/src/definitions/modules/transition.js index 9309f9e38..0c8e1beee 100644 --- a/src/definitions/modules/transition.js +++ b/src/definitions/modules/transition.js @@ -394,7 +394,6 @@ $.fn.transition = function() { } if(module.cache.style) { module.verbose('Restoring original style attribute', module.cache.style); - console.log('restoring cache', module.cache.style); $module.attr('style', module.cache.style); } if(module.is.looping()) {