hexo-theme-stellar/layout/_partial/scripts/lazyload.ejs

26 lines
819 B
Plaintext

<% if (theme.plugins.lazyload && theme.plugins.lazyload.enable) { %>
<script defer src="<%- theme.plugins.lazyload.js || 'https://cdn.jsdelivr.net/npm/vanilla-lazyload@17/dist/lazyload.min.js' %>"></script>
<script>
// https://www.npmjs.com/package/vanilla-lazyload
// Set the options globally
// to make LazyLoad self-initialize
window.lazyLoadOptions = {
elements_selector: ".lazyload",
threshold: 0
};
// Listen to the initialization event
// and get the instance of LazyLoad
window.addEventListener(
"LazyLoad::Initialized",
function (event) {
window.lazyLoadInstance = event.detail.instance;
},
false
);
document.addEventListener('DOMContentLoaded', function () {
lazyLoadInstance.update();
});
</script>
<% } %>