From b962d899f1587fd8b4a84fa198b2c38e897911a7 Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Thu, 23 Feb 2017 11:44:01 -0500 Subject: [PATCH] Fix visibility inside scroll context --- RELEASE-NOTES.md | 5 +++++ src/definitions/behaviors/visibility.js | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index c1a619c12..bd7a31283 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,5 +1,10 @@ ## RELEASE NOTES +### Version 2.2.10 - February 21, 2017 + +**Bugs** +**Visibility** - Fixed bug where using visibility with `context` setting on a scrollable context (with overflow) would cause callbacks to fire incorrectly + ### Version 2.2.9 - February 21, 2017 **Build Tools** diff --git a/src/definitions/behaviors/visibility.js b/src/definitions/behaviors/visibility.js index 73aeecf17..75129d5bd 100644 --- a/src/definitions/behaviors/visibility.js +++ b/src/definitions/behaviors/visibility.js @@ -422,6 +422,12 @@ $.fn.visibility = function(parameters) { return !(module.cache.element.width === 0 && module.cache.element.offset.top === 0); } return false; + }, + verticallyScrollableContext: function() { + return $context.get(0) !== window && $context.css('overflow-y') == 'auto'; + }, + horizontallyScrollableContext: function() { + return $context.get(0) !== window && $context.css('overflow-x') == 'auto'; } }, @@ -879,6 +885,13 @@ $.fn.visibility = function(parameters) { element.offset = $module.offset(); element.width = $module.outerWidth(); element.height = $module.outerHeight(); + // compensate for scroll in context + if(module.is.verticallyScrollableContext()) { + element.offset.top += $context.scrollTop(); + } + if(module.is.horizontallyScrollableContext()) { + element.offset.left += $context.scrollLeft(); + } // store module.cache.element = element; return element;