⚡ Use lazy loading image function & add image viewer. Close #65
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
|
||||
img {
|
||||
display: inline-block;
|
||||
max-width: 120px;
|
||||
max-height: 42px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
.site-author-image {
|
||||
border: $site-author-image-border-width solid $site-author-image-border-color;
|
||||
max-width: $site-author-image-width;
|
||||
width: $site-author-image-width;
|
||||
height: $site-author-image-width;
|
||||
padding: 2px;
|
||||
|
||||
@if $avatar_rounded {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
NexT.boot.registerEvents = function() {
|
||||
|
||||
NexT.utils.registerImageLoadEvent();
|
||||
NexT.utils.registerScrollPercent();
|
||||
// NexT.utils.registerCanIUseTag();
|
||||
NexT.utils.registerToolButtons();
|
||||
@@ -63,6 +64,7 @@ NexT.boot.refresh = function() {
|
||||
} else {
|
||||
NexT.utils.hideCommontes();
|
||||
}
|
||||
NexT.utils.registerImageViewer();
|
||||
|
||||
//TODO
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,37 @@ HTMLElement.prototype.wrap = function (wrapper) {
|
||||
};
|
||||
|
||||
NexT.utils = {
|
||||
registerImageLoadEvent: function() {
|
||||
var images = document.querySelectorAll('.sidebar img, .post-block img, .vendors-list img');
|
||||
|
||||
var callback = (entries) => {
|
||||
entries.forEach(item => {
|
||||
if (item.intersectionRatio > 0) {
|
||||
var ele = item.target;
|
||||
var imgSrc = ele.getAttribute('data-src');
|
||||
if (imgSrc) {
|
||||
var img = new Image();
|
||||
img.addEventListener('load', function() {
|
||||
ele.src = imgSrc;
|
||||
}, false);
|
||||
ele.src = imgSrc;
|
||||
// Prevent load image again
|
||||
ele.removeAttribute('data-src');
|
||||
}
|
||||
}
|
||||
})
|
||||
};
|
||||
|
||||
var observer = new IntersectionObserver(callback);
|
||||
images.forEach(img => {
|
||||
observer.observe(img);
|
||||
});
|
||||
},
|
||||
|
||||
registerImageViewer: function() {
|
||||
new Viewer(document.querySelector('.post-body'),{ navbar:2, toolbar:2 });
|
||||
},
|
||||
|
||||
registerToolButtons: function () {
|
||||
const buttons = document.querySelector('.tool-buttons');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user