diff --git a/src/echo.js b/src/echo.js index 53250cd..9e6c746 100644 --- a/src/echo.js +++ b/src/echo.js @@ -10,18 +10,27 @@ window.Echo = (function (window, document, undefined) { }; var _pollImages = function () { - for (var i = 0, len = store.length; i < len; i++) { - var self = store[i]; + var imgs = store.slice(); + for (var i = 0, len = imgs.length; i < len; i++) { + var self = imgs[i]; if (_inView(self)) { self.src = self.getAttribute('data-echo'); store.splice(i, 1); } } }; - + + var toArray (obj) { + var arr = []; + for (var i = 0, len = obj.length; i < len; i++) { + arr.push(obj[i]); + } + return arr; + } + var init = function () { store = document.querySelectorAll('[data-echo]'); - store = [].slice.call(store); + store = toArray(store); _pollImages(); window.onscroll = _pollImages; };