html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" href="newp.css" />
</head>
<body>
<nav class="navbar">
<img src="img/logo_zigzag.png" alt="logo" class="logo" />
<input
type="text"
class="search"
placeholder=" 검색어를 입력하세요"
/>
<img src="img/cart_zigzag.png" alt="cart" class="cart" />
</nav>
<nav class="homebar">
<button class="home1">홈</button>
<button class="home2">Brand</button>
<button class="home3">베스트</button>
<button class="home4">혜택</button>
<button class="home5">신상</button>
</nav>
<div class="section">
<input type="radio" class="slide" id="slide01" checked />
<input type="radio" class="slide" id="slide02" />
<input type="radio" class="slide" id="slide03" />
<div class="slidewrap">
<ul class="slidelist">
<li>
<a>
<label for="slide03" class="left"></label>
<!-- label을 slide03으로 설정했기 때문에,
이 left버튼을 누르면 같은 slide03을 id로 갖는 radio버튼이 눌린다. -->
<img src="./img/banner1.png" />
<label for="slide02" class="right"></label>
<!-- label을 slide02로 설정했기 때문에,
이 right버튼을 누르면 radio버튼의 slide02를 id로 가지는 버튼이 눌린다. -->
</a>
</li>
<li>
<a>
<label for="slide01" class="left"></label>
<img src="./img/banner2.png" />
<label for="slide03" class="right"></label>
<!-- 2번 이미지가 노출되었을 때는,
왼쪽 버튼은 slide01, 오른쪽 버튼은 slide03의 라벨이 적용되어
동일한 id값을 갖는 radio버튼이 눌리고, 해당 이미지로 이동한다. -->
<!-- 배너 이미지 출처:https://www.pinterest.co.kr/pin/3377768461355481/ -->
</a>
</li>
<li>
<a>
<label for="slide02" class="left"></label>
<!-- label을 slide03으로 설정했기 때문에,
이 left버튼을 누르면 같은 slide03을 id로 갖는 radio버튼이 눌린다. -->
<img src="./img/banner3.png" />
<label for="slide01" class="right"></label>
<!-- label을 slide02로 설정했기 때문에,
이 right버튼을 누르면 radio버튼의 slide02를 id로 가지는 버튼이 눌린다. -->
</a>
</li>
</ul>
</div>
</div>
<!-- 기존 -->
<!-- <article class="banner">
<div class="banner_slide">
<img
src="img/banner3_zigzag.png"
id="lastbanner"
alt="banner_img1"
class="banner_img"
/>
<div class="dots">
<button class="dot1"></button>
<button class="dot2" onclick="dot2click()"></button>
<!-- <button class="dot3"></button> -->
<!-- </div>
</div>
</article> -->
<box class="title">당신을 위한 추천 아이템</box>
<box class="filters">
<img src="img/filter_icon.png" alt="filter_icon" class="filter_icon" />
<!-- <p class="filter">filter</p> -->
<nav class="navbar2">
<button class="menu1" data-key="type" data-value="shirt">셔츠</button>
<button class="menu2" data-key="type" data-value="chardigan">
가디건
</button>
<button class="menu3" data-key="type" data-value="knit">니트</button>
<button class="menu4" data-key="type" data-value="pants">바지</button>
<button class="menu5" data-key="type" data-value="skirt">치마</button>
</nav>
</box>
<!-- title시멘틱 태그는 텍스트가 보이지 않는다. 왜일까? -->
<section class="items"></section>
<!-- <box class="title2">지그재그 베스트 100</box> -->
<!-- title시멘틱 태그는 텍스트가 보이지 않는다. 왜일까? -->
<section class="otheritems">
<div class="item2">
<img src="img/item2_img2.png" alt="${item.type}" class="item_img2" />
<box class="item_description">
<div class="item_mall">무아무아</div>
<div class="item_title">5color 무아 시그니처 와펜 후드 집업</div>
<box class="price">
<div class="item_discount">56%</div>
<div class="item_price">18,900</div>
</box>
</box>
</div>
<div class="item2">
<img src="img/item2_img3.png" alt="${item.type}" class="item_img2" />
<box class="item_description">
<div class="item_mall">무아무아</div>
<div class="item_title">5color 무아 시그니처 와펜 후드 집업</div>
<box class="price">
<div class="item_discount">56%</div>
<div class="item_price">18,900</div>
</box>
</box>
</div>
<div class="item2">
<img src="img/item2_img3.png" alt="${item.type}" class="item_img2" />
<box class="item_description">
<div class="item_mall">무아무아</div>
<div class="item_title">5color 무아 시그니처 와펜 후드 집업</div>
<box class="price">
<div class="item_discount">56%</div>
<div class="item_price">18,900</div>
</box>
</box>
</div>
<div class="item2">
<img src="img/item2_img3.png" alt="${item.type}" class="item_img2" />
<box class="item_description">
<div class="item_mall">무아무아</div>
<div class="item_title">5color 무아 시그니처 와펜 후드 집업</div>
<box class="price">
<div class="item_discount">56%</div>
<div class="item_price">18,900</div>
</box>
</box>
</div>
</section>
<div class="popup">
<box class="popup_box">
<img src="img/icon_popup.png" alt="popup_icon" class="popup_icon" />
<div class="popup_text">지금 보는 상품 10만원 할인받기 ></div>
<button class="popup_close">X</button>
</box>
</div>
<footer class="footer">
<box class="footerbox">
<button class="btn_footer">
<img src="img/icon1_footer.png" alt="icon1" class="imt_footer" />
<div class="text_footer">홈</div>
</button>
<button class="btn_footer">
<img src="img/icon2_footer.png" alt="" class="imt_footer" />
<div class="text_footer">쇼핑몰</div>
</button>
<button class="btn_footer">
<img src="img/icon3_footer.png" alt="" class="imt_footer" />
<div class="text_footer">모아보기</div>
</button>
<button class="btn_footer">
<img src="img/icon4_footer.png" alt="" class="imt_footer" />
<div class="text_footer">찜</div>
</button>
<button class="btn_footer">
<img src="img/icon5_footer.png" alt="" class="imt_footer" />
<div class="text_footer">마이페이지</div>
</button>
</box>
</footer>
<script defer src="src/main.js"></script>
</body>
</html>
css
::-webkit-scrollbar {
width: 3px;
height: 3 px;
}
::-webkit-scrollbar-thumb {
background-color: transparent;
}
::-webkit-scrollbar-track {
background-color: transparent;
}
:root {
--height-navbar: 40px;
--font-size-item: 10px;
--font-color: rgb(65, 65, 65);
--item-padding: 2px;
--item-height: 200px;
--item-width: 170px;
--item-border-radius: 5px;
}
body {
padding: 20px;
font-family: "paybook_font";
}
.navbar {
background-color: transparent;
display: flex;
justify-content: center;
justify-content: space-between;
align-items: center;
height: var(--height-navbar);
}
.logo {
height: var(--height-navbar);
}
.cart {
height: var(--height-navbar);
}
.search {
border: none;
border-radius: 50px;
background-color: rgb(245, 245, 245);
height: 33px;
width: 250px;
}
.homebar {
display: flex;
justify-content: center;
justify-content: space-around;
height: 50px;
}
.navbar2 {
display: flex;
justify-content: flex-end;
padding-top: 5px;
height: 30px;
}
.home1,
.home2,
.home3,
.home4,
.home5,
.menu1,
.menu2,
.menu3,
.menu4,
.menu5 {
font-weight: bold;
border: none;
background-color: transparent;
font-size: 15px;
color: gray;
cursor: pointer;
}
.section input[id*="slide"] {
display: none;
}
.section {
display: flex;
justify-content: center;
}
.section .slidewrap {
max-width: 100vw;
margin-bottom: 20px;
margin-top: 13px;
overflow: hidden;
}
.section .slidelist {
white-space: nowrap;
font-size: 0;
}
.section .slidelist > li {
display: inline-block;
vertical-align: middle;
width: 100%;
transition: all 0.5s;
}
.section .slidelist > li > a {
display: block;
position: relative;
}
.section .slidelist > li > a img {
width: 100%;
}
.section .slidelist label {
position: absolute;
z-index: 1;
top: 50%;
transform: translateY(-50%);
padding: 50px;
cursor: pointer;
}
.section .slidelist .left {
left: 0px;
background: url("./img/left.png") center center / 50% no-repeat;
}
.section .slidelist .right {
right: 0px;
background: url("./img/right.png") center center/50% no-repeat;
}
.section input[id="slide01"]:checked ~ .slidewrap .slidelist > li {
transform: translateX(0%);
}
.section input[id="slide02"]:checked ~ .slidewrap .slidelist > li {
transform: translateX(-105%);
}
.section input[id="slide03"]:checked ~ .slidewrap .slidelist > li {
transform: translateX(-209%);
}
.title,
.title2 {
background-color: transparent;
font-weight: bold;
color: var(--font-color);
height: 150px;
margin-top: 10px;
margin-left: 10px;
}
.filters {
display: flex;
align-items: center;
justify-content: flex-end;
}
.filter_icon {
height: 15px;
}
.items {
background-color: transparent;
height: 300px;
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 10px;
overflow-x: scroll;
}
.item {
width: var(--item-width);
height: var(--item-height);
padding: var(--item-padding);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
justify-content: space-between;
}
.item_mall {
font-size: var(--font-size-item);
padding: 1px;
font-weight: bold;
}
.item_title {
font-size: var(--font-size-item);
padding: 1px;
}
.item_price {
font-size: 15px;
font-weight: 900;
padding: 1px;
color: black;
}
.item_img {
height: var(--item-height);
width: var(--item-width);
border-radius: var(--item-border-radius);
margin-bottom: 7px;
}
.item_description {
color: var(--font-color);
width: var(--item-width);
height: 30%;
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: flex-start;
padding-bottom: 10px;
}
.otheritems {
display: flex;
flex-direction: row;
padding: 10px;
flex-wrap: wrap;
}
.item2 {
width: 47%;
padding: 5px;
}
.item_img2 {
height: 70%;
width: 100%;
padding: var(--item-padding);
}
.price {
display: flex;
align-items: center;
}
.item_discount {
font-size: 20px;
color: rgb(255, 51, 129);
font-weight: bold;
}
.popup {
position: fixed;
bottom: 80px;
left: 70px;
display: flex;
justify-content: center;
}
.popup_box {
height: 40px;
width: 400px;
border-radius: 7px;
background-color: rgb(44, 44, 44);
display: flex;
align-items: center;
}
.popup_icon {
height: 15px;
border-radius: 100px;
margin-left: 13px;
}
.popup_text {
margin-left: 15px;
color: rgba(228, 228, 228, 0.801);
font-size: 1px;
font-weight: 700;
}
.popup_close {
background-color: transparent;
border: none;
color: rgba(255, 255, 255, 0.404);
font-size: 5px;
margin-left: 170px;
cursor: pointer;
}
.footerbox {
position: fixed;
background-color: white;
left: 40px;
bottom: 0px;
width: 470px;
height: 70px;
display: flex;
justify-content: space-between;
}
.footer {
position: fixed;
bottom: 0px;
background-color: transparent;
margin-top: 20px;
border: 10px;
height: 100px;
display: flex;
justify-content: space-around;
}
.btn_footer {
font-size: 10px;
background-color: transparent;
border: none;
margin-top: 1px;
}
.text_footer {
color: gray;
margin-top: 4px;
}
.popup_icon.active {
visibility: hidden;
}
.popup_text.active {
color: transparent;
}
.popup_close.active {
color: transparent;
}
.popup_box.active {
background-color: transparent;
}
.home1:hover,
.home2:hover,
.home3:hover,
.home4:hover,
.home5:hover {
color: black;
border-bottom: 3px solid black;
}
js
function loaditems() {
return fetch("data/data.json")
.then((response) => response.json())
.then((json) => json.items);
}
function displayitems(items) {
const container = document.querySelector(".items");
container.innerHTML = items.map((item) => createHTMLString(item)).join("");
}
function createHTMLString(item) {
return `
<div class="item">
<img src="${item.image}" alt="${item.type}" class="item_img" />
<box class="item_description">
<div class="item_mall">${item.mall}</div>
<div class="item_title">${item.title}</div>
<div class="item_price">"${item.price}"</div>
</box>
</div>`;
}
function onButtonClick(event, items) {
const dataset = event.target.dataset;
const key = dataset.key;
const value = dataset.value;
console.log(event.target.dataset.key);
console.log(event.target.dataset.value);
if (key == null || value == null) {
return;
}
const filtered = items.filter((item) => item[key] === value);
console.log(filtered);
displayitems(filtered);
}
function setEventListeners(items) {
const logo = document.querySelector(".logo");
const menu = document.querySelector(".navbar2");
menu.addEventListener("click", (event) => onButtonClick(event, items));
}
loaditems()
.then((items) => {
displayitems(items);
setEventListeners(items);
})
.catch(console.log);
const popup_close = document.querySelector(".popup_close");
const popup_box = document.querySelector(".popup_box");
const popup_icon = document.querySelector(".popup_icon");
const popup_text = document.querySelector(".popup_text");
popup_close.addEventListener("click", () => {
popup_box.classList.toggle("active");
console.log("delete box");
popup_icon.classList.toggle("active");
console.log("delete icon");
popup_text.classList.toggle("active");
console.log("delete text");
popup_close.classList.toggle("active");
console.log("delete close icon");
console.log("창닫기 클릭");
});
function dot2click() {
const banner_img = document.querySelector("banner_img");
const dot1 = document.querySelector("dot1");
const dot2 = document.querySelector("dot2");
document
.getElementById("banner_img")
.setAttribute("src", "img/banner3_zigzag.png");
}