<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
#galleryZone {
text-align: center;
}
</style>
<script>
let num = 1;
const showGllery = function (direction) {
let flag = true;
if(direction) {
if(num === 9) {
alert("마지막 이미지 입니다.");
flag = false;
}
else {
num++;
}
}
else {
if (num === 1) {
alert("첫 이미지 입니다.");
flag = false;
}
else {
num--;
}
}
if (flag) {
let imgTag = document.getElementById("photo");
imgTag.setAttribute("src", "../img/pic_" + num + ".jpg");
}
}
</script>
</head>
<body>
<div id="galleryZone">
<p><img src="../img/pic_1.jpg" id="photo" alt="" width="100px" height="100px"></p>
<p>
<button onclick="showGllery(0)">이전</button>
<button onclick="showGllery(1)">다음</button>
</p>
</div>
</body>
</html>