修复布局更新问题
parent
6e6184f2b8
commit
f0344822cb
@ -1,9 +1,38 @@
|
||||
function debounce(func, wait, immediate) {
|
||||
let timeout;
|
||||
return function () {
|
||||
let context = this;
|
||||
let args = arguments;
|
||||
let later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
let callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) {
|
||||
func.apply(context, args);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
$(function () {
|
||||
console.log('IsekaiWidgets: Masonry extension loaded');
|
||||
new isekai.lib.Masonry('.isekai-masonry', {
|
||||
let masonry = new isekai.lib.Masonry('.isekai-masonry', {
|
||||
itemSelector: '.isekai-masonry-item',
|
||||
columnWidth: '.isekai-masonry-sizer',
|
||||
gutter: '.isekai-masonry-gutter-sizer',
|
||||
percentPosition: true
|
||||
});
|
||||
|
||||
let resizeObserver = new ResizeObserver(debounce(function () {
|
||||
console.log('masonry resize');
|
||||
masonry.layout();
|
||||
}, 100));
|
||||
|
||||
let items = document.querySelectorAll('.isekai-masonry-item');
|
||||
items.forEach(function (item) {
|
||||
resizeObserver.observe(item);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue