Changed lazyload

This commit is contained in:
zeldaroot 2021-01-04 01:53:25 +02:00
parent 1920c001fd
commit c78aa26843
2 changed files with 3 additions and 52 deletions

View File

@ -25,53 +25,4 @@
}
</script>
<script>
(function() {
var dataAllSrc = document.querySelectorAll('[data-cinemapress-src],[data-cinemapress-bg-src]');
var dataAllSrcCount = (dataAllSrc && dataAllSrc.length) || 0;
if (!dataAllSrcCount) return;
var dataAllSrcCountComp = 0;
var fSrc = {
'dataCountImage': function() {
dataAllSrcCountComp = dataAllSrcCountComp+1;
if (dataAllSrcCount && dataAllSrcCountComp >= dataAllSrcCount) {
dataAllSrcCount = 0;
var st;
window.addEventListener('load', function() {
clearTimeout(st);
fSrc['checkLoad']('dataSetImage');
});
st = setTimeout(function() {
fSrc['checkLoad']('dataSetImage');
}, 5000);
}
},
'dataSetImage': function(el) {
var src = el.dataset.cinemapressSrc;
var bgSrc = el.dataset.cinemapressBgSrc;
if (!src && !bgSrc) return;
var img = new Image();
img.src = src ? src : bgSrc;
img.onload = function() {
if (src) { el.src = src; }
else { el.style.backgroundImage = 'url("' + bgSrc + '")';}
}
},
'checkLoad': function(fn) {
if (!dataAllSrc) return;
dataAllSrc.forEach(function(src) {
if (typeof src.complete === 'undefined' || src.complete) {
fSrc[fn](src);
} else {
src.addEventListener('load', function() {
fSrc[fn](this);
}, { once: true });
}
});
}
}
fSrc['checkLoad']('dataCountImage');
})();
</script>
<%- page.codes.footer %>

View File

@ -127,7 +127,7 @@
<a href="<%- movie.url %>" class="line_cell clear_fix">
<div class="fl_l thumb">
<img class="cell_img" src="<%- movie.poster_min %>" data-cinemapress-src="<%- movie.poster %>" alt="<%= movie.title %>">
<img class="lazy cell_img" src="<%- movie.poster_min %>" data-src="<%- movie.poster %>" alt="<%= movie.title %>">
</div>
<div class="fl_l info">
<%= movie.title %>
@ -234,7 +234,7 @@
>
<a href="<%- movie.url %>" class="page_album_link">
<div class="page_album_thumb_wrap">
<img class="page_album_thumb" src="<%- movie.poster_min %>" data-cinemapress-src="<%- movie.poster %>"
<img class="lazy page_album_thumb" src="<%- movie.poster_min %>" data-src="<%- movie.poster %>"
alt="<%= movie.title %>">
</div>
<div class="page_album_title">
@ -289,7 +289,7 @@
<div class="clear_fix clear page_album_row">
<a href="<%- movie.url %>" class="page_album_link">
<div class="page_album_thumb_wrap">
<img class="page_album_thumb" src="<%- movie.poster_min %>" data-cinemapress-src="<%- movie.poster %>"
<img class="lazy page_album_thumb" src="<%- movie.poster_min %>" data-src="<%- movie.poster %>"
alt="<%= movie.title %>">
</div>
<div class="page_album_title">