css
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: cornsilk; }
li { list-style: none; }
.wrap {
max-width: 1080px;
min-width: 700px;
margin: 100px auto;
}
.list {}
.list li {
float: left;
width: 25%;
height: 200px;
padding: 6px;
}
.list li img {
width: 100%;
height: 100%;
object-fit: cover;
}
.pop {
position: fixed;
top: 0; left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .7);
display: none;
justify-content: center;
align-items: center;
}
.pop section {
position: relative;
padding: 50px;
background: #fff;
}
.pop section .pop_img {
max-height: 70vh;
}
.pop section .closeBtn {
position: absolute;
top: 0;
right: 0;
transform: translate(50%, -50%);
border-radius: 50%;
width: 50px;
height: 50px;
background: steelblue;
color: #fff;
text-decoration: none;
font-size: 30px;
text-align: center;
line-height: 40px;
}
.pop p {
text-align: center;
margin-top: 20px;
}
.pop p button {
border: none;
padding: 5px 10px;
cursor: pointer;
}
.pop.active { display: flex; }
html
<div class="wrap">
<h2>Modal PopUp</h2>
<ul class="list">
<li><img src="../img/pic1.jpg" alt=""></li>
<li><img src="../img/pic2.jpg" alt=""></li>
<li><img src="../img/pic3.jpg" alt=""></li>
<li><img src="../img/pic4.jpg" alt=""></li>
<li><img src="../img/pic5.jpg" alt=""></li>
<li><img src="../img/pic6.jpg" alt=""></li>
<li><img src="../img/pic7.jpg" alt=""></li>
<li><img src="../img/pic8.jpg" alt=""></li>
<li><img src="../img/pic9.jpg" alt=""></li>
</ul>
</div>
<div class="pop">
<section>
<img src="../img/pic1.jpg" alt="" class="pop_img">
<a href="#" class="closeBtn">x</a>
<p>
<button class="prev">< ์ด์ </button>
<button class="next">๋ค์></button>
</p>
</section>
</div>
js
const elList = document.querySelectorAll(".list li img"); // ์ธ๋ค์ผ ์ด๋ฏธ์ง
const elPop = document.querySelector(".pop") // ํ์
์ฐฝ
const elClose = document.querySelector(".closeBtn") // ๋ซ๊ธฐ ๋ฒํผ(ํ์
์)
const elPopImg = document.querySelector(".pop_img") // ํฐ ์ด๋ฏธ์ง(ํ์
์)
const elBtns = document.querySelector(".pop p") // ๋ฒํผ๋ค์ ๋ถ๋ชจ p(ํ์
)
let elTotalImg = elList.length;
let num = 0; // ์ด๋ฏธ์ง ์์๋ฅผ ๋ํ๋ผ ๋ณ์
// ์ธ๋ค์ผ ์ด๋ฏธ์ง๋ฅผ ๋๋ฅด๋ฉด ํ์
์ฐฝ ๋ฐ์
elList.forEach(function(item, index){ // index : parameter๋ก ๋ช ๋ฒ์งธ ์ ํํ๋์ง ์์์ฌ ์ ์์
item.onclick = function(){
elPop.classList.add("active");
elPopImg.src = item.src;
num = index; // ๋ช ๋ฒ์งธ ์์ดํ
์ ๋๋ ๋์ง ์์์์ ์ ์ญ๋ณ์ num์ ๋์
}
});
// ํ์
์ฐฝ ๋ซ๊ธฐ
elClose.onclick = function(e){
e.preventDefault();
elPop.classList.remove("active");
};
// ์ด์ , ๋ค์ ๋ฒํผ
elBtns.onclick = function(e){
if(e.target.classList.contains("prev")) { // e๊ฐ ๋ณด๋ด์ฃผ๋ ์ ๋ณด ์ค classList๋ง
if (num == 0) { // ๋ฌดํ๋ฃจํ
num = elTotalImg;
}
num = num - 1;
} else {
// if (elTotalImg - 1) {
// num = -1;
// }
// num++;
if (num != (elTotalImg - 1)) { // num์ด 8์ด ์๋๋๋ง 1์ถ๊ฐ
num++;
} else {
num = 0;
}
}
console.log("ํ์ฌ num : ", num);
elPopImg.src = elList[num].src;
};
css
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
background: #d3d3d3;
}
h1 { font-weight: normal; }
.banner { background: #fff; }
.banner div {
position: relative;
max-width: 1000px;
margin: auto;
height: 80px;
}
.banner span {
font-size: 3em; /* 16px * 3 */
line-height: 80px;
font-weight: bold;
}
.banner img {
height: 60px;
}
.banner a {
position: absolute;
top: 30px;
right: 0;
}
main {
display: table; /* ๋ถ๋ชจ ์์ */
width: 100%;
background: #818181;
}
main > div {
display: table-cell; /* ์์ ์์ */
height: 600px;
}
main > div > h1 {
font-size: 1px;
opacity: 0;
color: #fff;
text-align: center;
}
footer { padding: 30px 0; }
footer div {
max-width: 1000px;
margin: auto;
text-align: right;
}
footer small {
color: #fff;
font-size: 0.8em;
}
html
<div class="banner">
<div>
<img src="./img/logo.png" alt="">
<span>JUST DO IT.</span>
<a href="#">๋ซ๊ธฐ X</a>
</div>
</div>
<main>
<div>
<h1>Practice jQuery</h1>
</div>
</main>
<footer>
<div><small>jQuery ์ฐ์ต ํ์ด์ง ์
๋๋ค.</small></div>
</footer>
js
// $(document).ready(function () {});
$(function () {
// $("main h1").css({ fontSize: 150, opacity: 1 }); // ์ ๋๋ฉ์ด์
์์ด ํ ๋ฒ์ ๋ณ๊ฒฝ
$("main h1").animate({ fontSize: 150, opacity: 1, color: "red", "font-size": 150 }, 2000, "linear"); // ์ ๋๋ฉ์ด์
ํจ๊ณผ ์ ์ฉ
/*
A.animate({ key: value,... }, ์๊ฐ, easing)
- ์์ ๊ด๋ จ ์์ฑ์ ์ ์ฉโ
- css style ์์ฑ๋ ์ ์ฉ๋จ(fontSize = "font-size")
- easing : swing / linear
*/
$(".banner a").click(function () {
$(".banner").animate({ height: 0, opacity: 0 }, 500);
// $(".banner").slideUp(500); // ์์ ๋์ผํ๊ฒ ๋์
});
});
css
body {
font-family: Verdana, Geneva, Tahoma, sans-serif;
background: #d3d3d3;
}
h1 { font-weight: normal; }
.banner { background: #fff; }
.banner div {
position: relative;
max-width: 1000px;
margin: auto;
height: 80px;
}
.banner span {
font-size: 3em; /* 16px * 3 */
line-height: 80px;
font-weight: bold;
}
.banner img {
height: 60px;
}
.banner a {
position: absolute;
top: 30px;
right: 0;
}
main {
display: table; /* ๋ถ๋ชจ ์์ */
width: 100%;
background: #818181;
}
main > div {
display: table-cell; /* ์์ ์์ */
height: 600px;
}
.b1, .b2 {
width: 150px;
height: 150px;
margin: 50px;
}
.b1 { background: powderblue; }
.b2 { background: thistle; }
footer { padding: 30px 0; }
footer div {
max-width: 1000px;
margin: auto;
text-align: right;
}
footer small {
color: #fff;
font-size: 0.8em;
}
html
<div class="banner">
<div>
<img src="./img/logo.png" alt="">
<span>JUST DO IT.</span>
<a href="#">๋ซ๊ธฐ X</a>
</div>
</div>
<main>
<div>
<div class="b1"></div>
<div class="b2"></div>
</div>
</main>
<footer>
<div><small>jQuery ์ฐ์ต ํ์ด์ง ์
๋๋ค.</small></div>
</footer>
js
// $(document).ready(function () {});
$(function () {
$(".banner a").click(function () {
$(".banner").animate({ height: 0, opacity: 0 }, 500);
// $(".banner").slideUp(500); // ์์ ๋์ผํ๊ฒ ๋์
});
$(".b1").mouseover(function () {
$(this).animate({ "margin-left": "1000px" }, 2000, "swing", function () {
$(this).animate({ marginLeft: 50 }, 300);
});
});
$(".b2")
.mouseover(function () {
$(this).animate({ marginLeft: "+=100px" }, 300, "swing");
})
.click(function () {
$(this).animate({ marginLeft: "50px" }, 100, "swing");
});
// ๋ฉ์๋ ์ฒด์ธ - ์ ํ์๊ฐ ๊ฐ์ ๊ฒฝ์ฐ ๋งจ ์ ํ๋ฒ๋ง ์ ๊ณ .์ผ๋ก ์ฐ๊ฒฐ
});
/*
A.animate({ key: value,... }, ์๊ฐ, easing, ์ฝ๋ฐฑํจ์)
- ์์ ๊ด๋ จ ์์ฑ์ ์ ์ฉโ
- css style ์์ฑ๋ ์ ์ฉ๋จ(fontSize = "font-size")
- easing : swing / linear
*/
์์ 1
์์ 2
์์น์ด๋