From f1782da003b70e40b055b083cfce4909126ec9e1 Mon Sep 17 00:00:00 2001 From: "John D. Storey" Date: Thu, 15 Dec 2016 12:59:21 -0700 Subject: [PATCH 1/2] Adds support to define which elements to watch Adds support for items located off the side of the screen to the right, as well as watching for a parent to scroll incase they've locked the background in the use case of a modal or side-drawer element. --- jquery.unveil.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/jquery.unveil.js b/jquery.unveil.js index 8cfeb25..41a5b93 100644 --- a/jquery.unveil.js +++ b/jquery.unveil.js @@ -10,9 +10,10 @@ ;(function($) { - $.fn.unveil = function(threshold, callback) { + $.fn.unveil = function(threshold, callback, selectorsToWatch) { var $w = $(window), + $stw = selectorsToWatch ? $(selectorsToWatch) : $w, th = threshold || 0, retina = window.devicePixelRatio > 1, attrib = retina? "data-src-retina" : "data-src", @@ -36,16 +37,18 @@ var wt = $w.scrollTop(), wb = wt + $w.height(), et = $e.offset().top, - eb = et + $e.height(); + eb = et + $e.height(), + ww = $w.width(), + el = $e.offset().left; - return eb >= wt - th && et <= wb + th; + return eb >= wt - th && et <= wb + th && el <= ww; }); loaded = inview.trigger("unveil"); images = images.not(loaded); } - $w.on("scroll.unveil resize.unveil lookup.unveil", unveil); + $stw.on("scroll.unveil resize.unveil lookup.unveil transitionend.unveil transitionstart.unveil", unveil); unveil(); From 946a0f3f6a447684cc1ae40d108401cb64285c1e Mon Sep 17 00:00:00 2001 From: "John D. Storey" Date: Thu, 15 Dec 2016 13:01:13 -0700 Subject: [PATCH 2/2] fixes spacing --- jquery.unveil.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jquery.unveil.js b/jquery.unveil.js index 41a5b93..f32c892 100644 --- a/jquery.unveil.js +++ b/jquery.unveil.js @@ -37,11 +37,11 @@ var wt = $w.scrollTop(), wb = wt + $w.height(), et = $e.offset().top, - eb = et + $e.height(), - ww = $w.width(), - el = $e.offset().left; + eb = et + $e.height(), + ww = $w.width(), + el = $e.offset().left; - return eb >= wt - th && et <= wb + th && el <= ww; + return eb >= wt - th && et <= wb + th && el <= ww; }); loaded = inview.trigger("unveil");