일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- #CSS
- php
- #뉴스
- 솔루션
- #쇼핑몰
- #웹솔루션
- 사이트제작
- 홈페이지제작
- #jQuery
- #홈페이지
- jquery
- 해피씨지아이
- #동영상
- 이미지
- 해피CGI
- #솔루션
- #해피CGI
- CGIMALL
- #업종별
- 웹솔루션
- javascript
- #홈페이지제작
- 게시판
- #image
- #cgimall
- CSS
- #happycgi
- happycgi
- 홈페이지
- #이미지
- Today
- Total
웹솔루션개발 25년 노하우! 해피CGI의 모든것
[해피CGI][cgimall] Alpine.js ( Restaurant Menu Accordion ) 본문
웹프로그램밍 자료실/JAVA 자료
[해피CGI][cgimall] Alpine.js ( Restaurant Menu Accordion )
해피CGI윤실장 2025. 6. 18. 09:07Alpine.js를 사용한 메뉴판 입니다.
각 항목을 누르면 숨겨진 메뉴가 출력되는 형식입니다.
자세한 내용은 데모를 확인해 주시기 바랍니다.
HTML
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/collapse@3.x.x/dist/cdn.min.js"></script> <div class='wrapper'>
<div class='logo'></div>
<ul x-data='accordion' class='accordion'>
<template x-for='(items,category) in menu'>
<li>
<button @click='toggle(category)'>
<span x-text='category'></span>
</button>
<div x-show='activeItem === category && open' x-collapse.duration.800ms >
<ul class='accordion-list' >
<template x-for='item in items'>
<li>
<span x-text='item.name'></span>
<span x-text='item.price'></span>
</li>
</template>
</ul>
</div>
</li>
</template>
</ul>
</div>
|
CSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: grid;
place-items: center;
font: 1rem helvetica,sans-serif;
background-image: url('https://images.unsplash.com/photo-1616410731303-6affae095a0a?q=80&w=2501&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
& h1 {
font: 600 2.5rem helvetica,san-serif;
text-align: center;
margin-bottom: 1rem;
}
& ul { list-style-type: none; }
& .logo {
width: 40vmin;
height: 30vmin;
background: url('https://gist.githubusercontent.com/mondenoir/d6da82e3f052e43222a2a82848b7dd26/raw/fcca3c50abb242d7cd57f598c84a91c70a5e1b74/logo.svg') no-repeat center;
background-size: cover;
margin: 0 auto;
mix-blend-mode: multiply;
}
}
.accordion {
width: min(300px,90vw);
& > li:first-of-type { margin-top: 0; }
& > li { margin-top: -2px; }
& button {
width: 100%;
background-color: transparent;
font-size: 0.9rem;
line-height: 3.5;
text-transform: uppercase;
letter-spacing: 3px;
border: none;
border-top: 2px solid #000;
border-bottom: 2px solid #000;
outline: none;
cursor: pointer;
}
& .accordion-list {
display: grid;
grid-template-columns: repeat(2,1fr);
font-size: 0.7rem;
gap: 0.5rem 1.5rem;
padding: 1rem 0;
& li {
display: flex;
justify-content: space-between;
}
}
}
|
JS
function registerComponent() {
Alpine.data('accordion',function() {
return {
activeItem: 'appetizers',
open: true,
menu: {
appetizers: [
{ name: 'Caesar Salad', price: 8 },
{ name: 'Spring Rolls', price: 6 },
{ name: 'Stuffed Mushrooms', price: 9 },
{ name: 'Zuchini Fritters', price: 12 },
{ name: 'Coconut Shrimps', price: 15 },
{ name: 'Clam Bruschetta', price: 7 },
{ name: 'Crab Cake', price: 10 },
{ name: 'Clam Chowder', price: 6 },
{ name: 'Beef Stew', price: 6 },
],
main: [
{ name: 'Cedar-Plank Salmon', price: 18 },
{ name: 'Lobster Gnocchi', price: 25 },
{ name: 'Chicken Lasagna', price: 15 },
{ name: 'Grilled Spareribs', price: 30 },
{ name: 'Scallops Risotto', price: 20 },
{ name: 'New York Steak', price: 18 },
{ name: 'Jambalaya', price: 15 },
{ name: 'Seafood Pasta', price: 18 },
{ name: 'Beef Stroganoff', price: 18 },
{ name: 'Thai Green Curry', price: 20 },
],
desserts: [
{ name: 'Caramel Flan', price: 5 },
{ name: 'Old English Trifle', price: 8 },
{ name: 'Budapest Roll', price: 6 },
{ name: 'Nanimo Bar', price: 5 },
{ name: 'Lemon Drizzle Cake', price: 4 },
],
drinks: [
{ name: 'Martini', price: 7 },
{ name: 'Manhattan', price: 8 },
{ name: 'Cosmopolitan', price: 8 },
{ name: 'Whiskey Sour', price: 6 },
{ name: 'Mojito', price: 6 },
{ name: 'Margaria', price: 7 },
{ name: 'Old Fashion', price: 6 },
{ name: 'Bloody Mary', price: 9 },
{ name: 'White Russian', price: 7 },
{ name: 'Coffee', price: 3 },
{ name: 'Soda', price: 2 },
],
},
toggle(item) {
this.activeItem = (this.activeItem === item ? null : item);
this.open = true;
},
}
});
}
document.addEventListener('alpine:init',registerComponent,false);
|
'웹프로그램밍 자료실 > JAVA 자료' 카테고리의 다른 글
[해피CGI][cgimall] Alpine.js ( Masonry Gallery + Lazy Loading ) (0) | 2025.06.23 |
---|---|
[해피CGI][cgimall] 동기화된 입력을 제공하는 jQuery 범위 슬라이더 플러그인 (0) | 2025.06.12 |
[해피CGI][cgimall] 사용자 정의 함수 트리거 jQuery 플러그인 - onScreen.js (0) | 2025.06.11 |
[해피CGI][cgimall] jQuery 기반의 바코드 생성기 (Data Matrix 가능) (0) | 2025.05.27 |
[해피CGI][cgimall] jQuery 카운트다운 타이머 플러그인 (0) | 2025.05.26 |
Comments