@egjs/infinitegrid
Version:
A module used to arrange elements including content infinitely according to grid type. With this module, you can implement various grids composed of different card elements whose sizes vary. It guarantees performance by maintaining the number of DOMs the
160 lines (133 loc) • 2.72 kB
HTML
<div class="container">
</div>
<style>
html,
body {
position: relative;
margin: 0;
padding: 0;
height: 100%;
background: #fff;
}
a {
color: unset;
text-decoration: none;
}
.header {
text-align: center;
background: #333;
color: #fff;
padding: 20px 0px;
margin: 0;
margin-bottom: 10px;
}
.description {
padding: 6px 30px;
margin: 0;
font-weight: 400;
}
.description li {
padding: 3px 0px;
}
.container {
width: 100%;
height: 600px;
background: #f55;
}
.item {
display: inline-block;
width: 250px;
opacity: 1;
}
.horizontal .item {
width: auto;
height: 250px;
}
.item .thumbnail {
max-height: 300px;
overflow: hidden;
border-radius: 8px;
}
.equal .item .thumbnail {
height: 140px;
}
.equal.horizontal .item .thumbnail {
height: auto;
width: 140px;
}
.item .thumbnail img {
width: 100%;
border-radius: 8px;
}
.horizontal .item .thumbnail img {
width: auto;
height: 210px;
}
.item .info {
margin-top: 10px;
font-weight: bold;
color: #777;
}
.item.animate {
transition: opacity ease 1s;
transition-delay: 0.2s;
opacity: 1;
}
.loading {
position: absolute;
width: 100%;
height: 50px;
display: none;
}
.loading span {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.horizontal .loading {
width: 200px;
height: 100%;
}
.placeholder {
background: #eee;
border-radius: 10px;
width: 250px;
height: 300px;
}
</style>
<script src="../../dist/infinitegrid.js"></script>
<script>
function getItems(nextGroupKey, count) {
const nextItems = [];
for (let i = 0; i < count; ++i) {
const num = nextGroupKey * count + i;
nextItems.push(`<div class="item">
<img src="https://naver.github.io/egjs-infinitegrid/assets/image/${(num % 33) + 1}.jpg" alt="egjs" style="width: 100%;height: 100%;"/>
</div>`);
}
return nextItems;
}
const ig = new InfiniteGrid.FrameInfiniteGrid(".container", {
container: false,
useFit: true,
useRecycle: true,
horizontal: false,
frame: [
[1, 1, 2, 2, 3],
[1, 1, 4, 5, 5],
],
gap: 5,
});
// ig.setPlaceholder({ html: `<div class="placeholder">Placeholder</div>` })
ig.on("requestAppend", e => {
if (e.isVirtual) {
// console.log("placeholder");
ig.append(getItems(e.nextGroupKey, 10), e.nextGroupKey);
} else {
const nextGroupKey = (+e.groupKey || 0) + 1;
ig.append(getItems(nextGroupKey, 10), nextGroupKey);
}
});
ig.renderItems();
</script>