<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>04-02_image</title>
<script src="<https://code.jquery.com/jquery-3.7.1.js>"></script>
<style type="text/css">
* { margin: 0; padding: 0; }
a {
font-family: "맑은 고딕", sans-serif;
font-size: 12px;
color: black;
text-decoration: none;
}
/* #visual */
#visual {
border: 1px solid red;
width: 1000px;
margin: 0 auto;
position: relative;
}
#visual #pic{
height: 500px;
overflow: hidden;
position: relative;
}
#visual #pic > div {
position: absolute;
left: 0;
top: 0;
display: none;
}
#visual #control {
position: absolute;
width: 200%;
bottom: 20px;
}
#visual #control a {
display: inline-block;
width: 30px;
height: 30px;
background-color: black;
color: white;
font-weight: bold;
line-height: 30px;
border-radius: 5px;
margin: 0 4px;
text-align: center;
}
#visul #control a.on{
background-color: red;
}
</style>
</head>
<body>
<br/>
<div id="visual">
<div id="pic">
<div><a href="#"><img src="../../image/jquery_image/f1.jpg"></a></div>
<div><a href="#"><img src="../../image/jquery_image/f2.jpg"></a></div>
<div><a href="#"><img src="../../image/jquery_image/f3.jpg"></a></div>
<div><a href="#"><img src="../../image/jquery_image/f4.jpg"></a></div>
</div>
<div id="control">
<a href="#">1</a>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
</div>
</div>
<!-- javascript -->
<script type="text/javascript">
$(document).ready(function(){
$("#control a").click(function(){
let num = Number($(this).text()) - 1 ; // -1 하는 이유 -- 배열이라 0번부터 적용
$(this).addClass("on").siblings().removeClass("on"); // 클릭된 요소만 addClass() 적용
$("#pic > div").filter(":visible").stop(true).fadeOut(100).end().eq(num).stop(true).fadeIn(100);
// visible 요소는 fadeOut(), 클릭한 요소는 fadeIn()
});
$("#control a:first").addClass("on").add("#pic > div:first").show();
// 웹페이지 로드시 첫번째 이미지 표시.
});
</script>
</body>
</html>