mirror of https://github.com/toddmotto/echo.git
Todd Motto
12 years ago
4 changed files with 29 additions and 33 deletions
@ -1,10 +1,10 @@ |
|||||||
/*! |
/*! |
||||||
* Echo |
* Echo |
||||||
* @version 1.0.0 |
* @version 1.1.0 |
||||||
* @author Todd Motto http://toddmotto.com
|
* @author Todd Motto http://toddmotto.com
|
||||||
* Project: https://github.com/toddmotto/echo
|
* Project: https://github.com/toddmotto/echo
|
||||||
* |
* |
||||||
* Raw JavaScript lazy-loading images with HTML5 data-* attributes. |
* Raw JavaScript lazy-loading images with HTML5 data-* attributes. |
||||||
* Copyright 2013. MIT licensed. |
* Copyright 2013. MIT licensed. |
||||||
*/ |
*/ |
||||||
window.echo=function(a,b){"use strict";var c=function(a){this.elem=a,this.render(),this.listen()},d=[],e=function(c){var d=c.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(a.innerHeight||b.documentElement.clientHeight)},f=function(a,b){a.src=a.getAttribute("data-echo"),b&&b()},g=function(a,b){-1!==d.indexOf(a)&&d.splice(b,1)},h=function(){for(var a=0;a<d.length;a++){var b=d[a];e(b)&&f(b,g(b,a))}};c.prototype={init:function(){d.push(this.elem)},render:function(){b.addEventListener?b.addEventListener("DOMContentLoaded",h,!1):a.onload=h},listen:function(){a.onscroll=h}};for(var i=b.querySelectorAll("img[data-echo]"),j=0;j<i.length;j++)new c(i[j]).init()}(window,document); |
window.echo=function(a,b){"use strict";var c=function(a){this.elem=a},d=[],e=function(c){var d=c.getBoundingClientRect();return(d.top>=0&&d.left>=0&&d.top)<=(a.innerHeight||b.documentElement.clientHeight)},f=function(a,b){a.src=a.getAttribute("data-echo"),b&&b()},g=function(a,b){-1!==d.indexOf(a)&&d.splice(b,1)},h=function(){for(var a=0;a<d.length;a++){var b=d[a];e(b)&&f(b,g(b,a))}};c.prototype={init:function(){d.push(this.elem)}};for(var i=b.querySelectorAll("img[data-echo]"),j=0;j<i.length;j++)new c(i[j]).init();b.addEventListener?b.addEventListener("DOMContentLoaded",h,!1):a.onload=h,a.onscroll=h}(window,document); |
Loading…
Reference in new issue