-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_changeImg03.html
More file actions
39 lines (37 loc) · 1.1 KB
/
Copy pathexample_changeImg03.html
File metadata and controls
39 lines (37 loc) · 1.1 KB
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
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="kr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="galleryZone">
<div><img src="images/pic_1.jpg" id='photo' alt=""></div>
<div class="btn">
<button type="button">이전</button>
<button type="button">다음</button>
</div>
</div>
<script>
let imgNum = 1;
let img = document.querySelector("#photo");
let btn = document.querySelectorAll(".btn button");
for(let i=0;i<btn.length;i++){
btn[i].addEventListener("click",() => {
if(i===1){
if(imgNum===8) return;
imgNum++;
console.log("다음"+i);
}
else{
if(imgNum===1) return;
imgNum--;
console.log("이전"+i);
}
img.setAttribute('src',`images/pic_${imgNum}.jpg`);
});
}
</script>
</body>
</html>