From 34134d6fe6492e9919ed05a817ac6e4addfc883b Mon Sep 17 00:00:00 2001 From: Chen Fengyuan Date: Sat, 10 Mar 2018 19:53:18 +0800 Subject: [PATCH] fix: should define `viewing` first --- src/js/methods.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/js/methods.js b/src/js/methods.js index 3381c83..b35441d 100644 --- a/src/js/methods.js +++ b/src/js/methods.js @@ -263,24 +263,6 @@ export default { once: true, }); - if (image.complete) { - this.load(); - } else { - addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), { - once: true, - }); - - if (this.timeout) { - clearTimeout(this.timeout); - } - - // Make the image visible if it fails to load within 1s - this.timeout = setTimeout(() => { - removeClass(image, CLASS_INVISIBLE); - this.timeout = false; - }, 1000); - } - this.viewing = { abort() { removeListener(element, EVENT_VIEWED, onViewed); @@ -301,6 +283,24 @@ export default { }, }; + if (image.complete) { + this.load(); + } else { + addListener(image, EVENT_LOAD, onLoad = this.load.bind(this), { + once: true, + }); + + if (this.timeout) { + clearTimeout(this.timeout); + } + + // Make the image visible if it fails to load within 1s + this.timeout = setTimeout(() => { + removeClass(image, CLASS_INVISIBLE); + this.timeout = false; + }, 1000); + } + return this; },