From 35dbf640377d86e6989cda46e4fe30456df9f80b Mon Sep 17 00:00:00 2001 From: Florian THIERRY Date: Mon, 13 Jun 2016 15:04:47 +0200 Subject: [PATCH] Add dom context --- jquery.unveil.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/jquery.unveil.js b/jquery.unveil.js index 8cfeb25..b420711 100644 --- a/jquery.unveil.js +++ b/jquery.unveil.js @@ -10,14 +10,20 @@ ;(function($) { - $.fn.unveil = function(threshold, callback) { + $.fn.unveil = function(dom, threshold, callback) { var $w = $(window), th = threshold || 0, retina = window.devicePixelRatio > 1, attrib = retina? "data-src-retina" : "data-src", images = this, - loaded; + loaded, + $wOffset = 0; + + if(typeof(dom) !== 'undefined' && $(dom).length > 0){ + $w = $(dom); + $wOffset = $(dom).offset().top; + } this.one("unveil", function() { var source = this.getAttribute(attrib); @@ -35,7 +41,7 @@ var wt = $w.scrollTop(), wb = wt + $w.height(), - et = $e.offset().top, + et = $e.offset().top - $wOffset, eb = et + $e.height(); return eb >= wt - th && et <= wb + th;