제이쿼리 멀티탭 구현 두번째
멀티탭 구현 두번째
See the Pen by yoonbitnara (@yoonbitnara) on CodePen.
상세코드
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="style/style.css">
</head>
<body>
<h1>멀티탭구현2</h1>
<div id="wrap">
<div id="tabBtnArea">
<button type="button" class="tabBtnSelected">
공지사항
</button>
<button type="button">
갤러리
</button>
</div>
<div id="notice" class="tabContents">
<table>
<tbody>
<tr>
<td>3월 재입고 품목을 알려드립니다.</td>
<td>2020.03.14</td>
</tr>
<tr>
<td>반품/환불 규정에 대해 알려드립니다.</td>
<td>2020.03.14</td>
</tr>
<tr>
<td>S/S 시즌 신규 의류 신상품 안내</td>
<td>2020.03.14</td>
</tr>
<tr>
<td>신규회원 대상 할인 이벤트 안내</td>
<td>2020.03.14</td>
</tr>
</tbody>
</table>
</div>
<div id="gallery" class="tabContents">
<table>
<tbody>
<tr>
<td>
<img src="images/icon1.jpg" alt="image1">
</td>
<td>
<img src="images/icon2.jpg" alt="image2">
</td>
<td>
<img src="images/icon3.jpg" alt="image3">
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- div#wrap -->
<script src="lib/jquery-3.6.0.min.js"></script>
<script src="script/script.js"></script>
</body>
</html>
CSS
@charset "UTF-8";
h1 {
width: 460px;
text-align: center;
margin: 0 auto;
}
div#wrap {
width: 430px;
padding: 40px 20px;
border: 1px solid #000;
margin: 20px auto;
}
button {
font-size: 18px;
font-weight: bold;
padding: 2 14px;
border: 1px solid #aaa;
position: relative;
top: 1px;
cursor: pointer;
}
button:first-child {
left: 1px;
}
button.tabBtnSelected {
border-bottom: 1px solid #fff;
background-color: #fff;
}
table {
width: 400px;
height: 140px;
margin: 0 auto;
}
/* table, td {
border: 1px solid #000;
} */
div#gallery {
display: none;
}
div#gallery td {
text-align: center;
}
div.tabContents {
border: 1px solid #aaa;
}
div#tabBtnArea {
display: flex;
padding-left: 10px;
}
jQuery
$(function(){
$("button").click(function(){
$("button").css({
"background-color": "#efefef",
"border": "1px solid #aaa"
});
$(this).css({
"background-color": "#fff",
"border-bottom-color": "#fff"
});
let btnTxt = $(this).text();
btnTxt = btnTxt.trim();
$("div.tabContents").css({"display": "none"});
if (btnTxt == "공지사항") {
$("div#notice").css({"display": "block"});
} else if (btnTxt == "갤러리") {
$("div#gallery").css({"display": "block"});
}
});
});
Leave a comment