Jony/plugin/joe.lazyload.js
2021-01-27 13:00:55 +08:00

1 line
1.1 KiB
JavaScript

'use strict';var _createClass=function(){function a(b,c){for(var e,d=0;d<c.length;d++)e=c[d],e.enumerable=e.enumerable||!1,e.configurable=!0,'value'in e&&(e.writable=!0),Object.defineProperty(b,e.key,e)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var LazyLoad=function(){function a(b){_classCallCheck(this,a),this.imglist=Array.from($(b)),this.init()}return _createClass(a,[{key:'canILoad',value:function canILoad(){for(var b=this.imglist,c=b.length;c--;)this.getBound(b[c])&&this.loadImage(b[c],c)}},{key:'getBound',value:function getBound(b){var c=b.getBoundingClientRect(),d=window.innerHeight;return c.top<=d}},{key:'loadImage',value:function loadImage(b,c){var d=b.getAttribute('data-original');b.src=d,this.imglist.splice(c,1)}},{key:'bindEvent',value:function bindEvent(){var b=this;$(window).on('scroll',function(){return b.imglist.length&&b.canILoad()}),$(window).on('resize',function(){return b.imglist.length&&b.canILoad()})}},{key:'init',value:function init(){this.canILoad(),this.bindEvent()}}]),a}();