mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-16 01:08:41 +00:00
fixes #34
This commit is contained in:
parent
5565d0a11e
commit
de25c32501
|
|
@ -20,6 +20,8 @@
|
||||||
*/
|
*/
|
||||||
jsOMS.UI.GeneralUI = function ()
|
jsOMS.UI.GeneralUI = function ()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
this.visObs = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,6 +41,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bindHref(e);
|
this.bindHref(e);
|
||||||
|
this.bindLazyLoad(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,4 +65,40 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind & rebind UI element.
|
||||||
|
*
|
||||||
|
* @param {Object} [e] Element id
|
||||||
|
*
|
||||||
|
* @method
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
jsOMS.UI.GeneralUI.prototype.bindLazyLoad = function (e)
|
||||||
|
{
|
||||||
|
e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]');
|
||||||
|
const length = e.length;
|
||||||
|
|
||||||
|
if(!this.visObs && window.IntersectionObserver) {
|
||||||
|
this.visObs = new IntersectionObserver(function(eles, obs) {
|
||||||
|
eles.forEach(ele => {
|
||||||
|
if (ele.intersectionRatio > 0) {
|
||||||
|
obs.unobserve(ele.target);
|
||||||
|
ele.target.src = ele.target.dataset.lazyload;
|
||||||
|
delete ele.target.dataset.lazyload;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i < length; i++) {
|
||||||
|
if(!this.visObs) {
|
||||||
|
e[i].src = e[i].dataset.lazyload;
|
||||||
|
delete e[i].dataset.lazyload;
|
||||||
|
} else {
|
||||||
|
this.visObs.observe(e[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user