jquery.unveil.min.js 945 B

1234567891011
  1. /**
  2. * jQuery Unveil
  3. * A very lightweight jQuery plugin to lazy load images
  4. * http://luis-almeida.github.com/unveil
  5. *
  6. * Licensed under the MIT license.
  7. * Copyright 2013 Luís Almeida
  8. * https://github.com/luis-almeida
  9. */
  10. ;(function($){$.fn.unveil=function(threshold,callback){var $w=$(window),th=threshold||0,retina=window.devicePixelRatio>1,attrib=retina?"data-src-retina":"data-src",images=this,loaded;this.one("unveil",function(){var source=this.getAttribute(attrib);source=source||this.getAttribute("data-src");if(source){this.setAttribute("src",source);if(typeof callback==="function")callback.call(this);}});function unveil(){var inview=images.filter(function(){var $e=$(this),wt=$w.scrollTop(),wb=wt+$w.height(),et=$e.offset().top,eb=et+$e.height();return eb>=wt-th&&et<=wb+th;});loaded=inview.trigger("unveil");images=images.not(loaded);}$w.scroll(unveil);$w.resize(unveil);unveil();return this;};})(window.jQuery||window.Zepto);