mirror of https://github.com/toddmotto/echo.git
Todd Motto
11 years ago
5 changed files with 103 additions and 48 deletions
@ -1,8 +1,8 @@
|
||||
/*! |
||||
* Echo v1.3.0 |
||||
* Lazy-loading images with data-* attributes |
||||
* Echo v1.4.0 |
||||
* Lazy-loading with data-* attributes, offsets and throttle options |
||||
* Project: https://github.com/toddmotto/echo
|
||||
* by Todd Motto: http://toddmotto.com
|
||||
* Copyright. MIT licensed. |
||||
*/ |
||||
window.Echo=function(a,b){"use strict";var c,d=function(c){var d=c.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(a.innerHeight||b.documentElement.clientHeight)},e=function(){for(var a=0;a<c.length;a++){var b=c[a];d(b)&&(b.src=b.getAttribute("data-echo"),[].indexOf&&-1!==[].slice.call(c).indexOf(b)&&[].slice.call(c).splice(a,1))}},f=function(){c=b.querySelectorAll("[data-echo]"),e(),a.onscroll=e};return{init:f}}(window,document); |
||||
window.Echo=function(a,b){"use strict";var c,d,e,f=[],g=function(d){var e=d.getBoundingClientRect();return(e.top>=0&&e.left>=0&&e.top)<=(a.innerHeight||b.documentElement.clientHeight)+parseInt(c)},h=function(){for(var a=f.length;a--;){var b=f[a];g(b)&&(b.src=b.getAttribute("data-echo"),f.splice(a,1))}},i=function(){clearTimeout(e),e=setTimeout(h,d)},j=function(e){var g=b.querySelectorAll("[data-echo]"),h=e||{};c=h.offset||0,d=h.throttle||250;for(var j=0;j<g.length;j++)f.push(g[j]);b.addEventListener?a.addEventListener("scroll",i,!1):a.attachEvent("onscroll",i)};return{init:j,render:i}}(window,document); |
Loading…
Reference in new issue