일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- #쇼핑몰
- javascript
- CGIMALL
- #웹솔루션
- 웹솔루션
- #jQuery
- #해피CGI
- 해피CGI
- #동영상
- php
- 게시판
- #솔루션
- 이미지
- jquery
- #happycgi
- #cgimall
- 해피씨지아이
- CSS
- #홈페이지
- #image
- #업종별
- #이미지
- 솔루션
- #CSS
- 사이트제작
- 홈페이지
- #뉴스
- 홈페이지제작
- #홈페이지제작
- happycgi
- Today
- Total
웹솔루션개발 25년 노하우! 해피CGI의 모든것
[해피CGI][cgimall] Alpine.js ( Masonry Gallery + Lazy Loading ) 본문
웹프로그램밍 자료실/JAVA 자료
[해피CGI][cgimall] Alpine.js ( Masonry Gallery + Lazy Loading )
해피CGI윤실장 2025. 6. 23. 09:09Alpine.js를 사용하여 html 블록을 반복 생성하게 만든 디자인 입니다.
스크롤 시 설정한 개수 만큼 이미지가 자동으로 출력되게 되어있습니다.
자세한 내용은 데모를 확인해 주시기 바랍니다.
HTML
<div class='wrapper'>
<div x-data class='gallery'>
<template x-for='i in 300' :key='i'>
<li x-data='observeImages' x-intersect.margin.200px.once='loadImage'>
<img x-ref='img'>
</li>
</template>
</div>
</div>
|
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
background-color: black;
padding: 0.5rem;
}
.gallery {
column-count: 1;
column-gap: 0.5rem;
list-style-type: none;
& li {
break-inside: avoid;
min-height: 30vmin;
margin-bottom: 0.5rem;
background-color: #222;
& img {
display: block;
width: 100%;
object-fit: cover;
filter: grayscale(100%);
transition: opacity 0.3s;
}
}
}
@media (width > 500px) {
.gallery {
columns: 2;
}
}
@media (width > 900px) {
.gallery {
columns: 3;
}
}
|
JS
function registerComponent() {
Alpine.data('observeImages',function() {
return {
random(min,max) {
return Math.floor(min + Math.random() * (max-min));
},
loadImage() {
const id = this.random(100,1000);
const width = this.random(300,600);
const height = this.random(200,500);
const img = this.$refs.img;
img.width = width;
img.height = height;
img.src = `https://picsum.photos/seed/${id}/600/400`;
img.style.opacity = 0;
img.addEventListener('load',() => img.style.opacity = 1,false);
},
}
});
}
document.addEventListener('alpine:init',registerComponent,false);
|
'웹프로그램밍 자료실 > JAVA 자료' 카테고리의 다른 글
[해피CGI][cgimall] Easy Tree - Query와 Bootstrap 3를 활용한 멋진 트리 뷰 (0) | 2025.06.30 |
---|---|
[해피CGI][cgimall] table2excel - jQuery 로 HTML을 EXCEL 로 변환하기 (0) | 2025.06.27 |
[해피CGI][cgimall] Alpine.js ( Restaurant Menu Accordion ) (0) | 2025.06.18 |
[해피CGI][cgimall] 동기화된 입력을 제공하는 jQuery 범위 슬라이더 플러그인 (0) | 2025.06.12 |
[해피CGI][cgimall] 사용자 정의 함수 트리거 jQuery 플러그인 - onScreen.js (0) | 2025.06.11 |
Comments