From a6c85c7b337c32e8885aba8e683d96c5d924f846 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 5 Sep 2013 22:57:08 +0100 Subject: [PATCH 1/2] Added ability to specify a scrollable parent object --- jquery.appear.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jquery.appear.js b/jquery.appear.js index ff0b764..94e4731 100644 --- a/jquery.appear.js +++ b/jquery.appear.js @@ -13,11 +13,12 @@ var check_binded = false; var check_lock = false; + var $window = $(window); var defaults = { interval: 250, - force_process: false + force_process: false, + scrolling_parent: $window } - var $window = $(window); var $prior_appeared; @@ -76,7 +77,11 @@ setTimeout(process, opts.interval); }; - $(window).scroll(on_check).resize(on_check); + opts.scrolling_parent.scroll(on_check); + // resize event is only triggered for $window so no point setting it on scrolling_parent + // if scrolling_parent is resizeable you should make sure your resizing code calls .resize() + $window.resize(on_check); + check_binded = true; } From fa13b15c797a95c975292e87b2f760d78dbc499a Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Tue, 29 Oct 2013 23:21:29 +0000 Subject: [PATCH 2/2] fixed for scrollable parent object --- jquery.appear.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/jquery.appear.js b/jquery.appear.js index 94e4731..e88076f 100644 --- a/jquery.appear.js +++ b/jquery.appear.js @@ -21,6 +21,7 @@ } var $prior_appeared; + var scrolling_parent; function process() { check_lock = false; @@ -46,16 +47,15 @@ return false; } - var window_left = $window.scrollLeft(); - var window_top = $window.scrollTop(); var offset = $element.offset(); - var left = offset.left; - var top = offset.top; + // calculate pos of element relative to the visible part of the scrolling_parent + var left = offset.left - scrolling_parent.offset().left; + var top = offset.top - scrolling_parent.offset().top; - if (top + $element.height() >= window_top && - top - ($element.data('appear-top-offset') || 0) <= window_top + $window.height() && - left + $element.width() >= window_left && - left - ($element.data('appear-left-offset') || 0) <= window_left + $window.width()) { + if ((top + $element.height() >= 0) && + (top - ($element.data('appear-top-offset') || 0) <= scrolling_parent.height()) && + (left + $element.width() >= 0) && + (left - ($element.data('appear-left-offset') || 0) <= scrolling_parent.width())) { return true; } else { return false; @@ -77,7 +77,8 @@ setTimeout(process, opts.interval); }; - opts.scrolling_parent.scroll(on_check); + scrolling_parent = opts.scrolling_parent; + scrolling_parent.scroll(on_check); // resize event is only triggered for $window so no point setting it on scrolling_parent // if scrolling_parent is resizeable you should make sure your resizing code calls .resize() $window.resize(on_check);