<!DOCTYPE html>
<html lang="ko">
<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>full_page_indicator</title>
<script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="./js/jquery.scrollTo.min.js"></script>
<script>
$(function () {
const btn = $(".lnb li");
const section = $(".contents section");
$(".lnb").css("top", $(window).height() / 2 - $(".lnb").height() / 2);
$(window).scroll(function () {
let point =
$(this).scrollTop() +
$(window).height() / 2 -
$(".lnb").height() / 2;
$(".lnb").stop().animate({ top: point }, 500);
section.each(function () {
let sectionPoint = $(window).scrollTop();
let target = $(this);
let i = target.index();
if (sectionPoint >= target.offset().top) {
btn.removeClass("on");
btn.eq(i).addClass("on");
}
});
});
btn.click(function () {
let target = $(this);
let i = target.index();
let targetSection = section.eq(i);
let point = targetSection.offset().top;
$("html, body").stop().animate({ scrollTop: point }, 1000);
});
});
</script>
<style>
* {
margin: 0;
padding: 0;
}
li {
list-style: none;
}
.lnb {
position: absolute;
right: 20px;
}
.lnb li {
background-color: #333;
width: 25px;
height: 25px;
border-radius: 25px;
margin-bottom: 10px;
}
.lnb li:last-child {
margin-bottom: 0;
}
.lnb li a {
display: block;
font-size: 16px;
color: white;
text-decoration: none;
text-align: center;
line-height: 25px;
}
.lnb li.on a {
color: crimson;
}
.contents section {
height: 100vh;
font-size: 100px;
display: flex;
justify-content: center;
}
.contents section img {
height: 100vh;
}
#page01 {
background-color: palevioletred;
}
#page02 {
background-color: teal;
}
#page03 {
background-color: orangered;
}
#page04 {
background-color: dimgray;
}
</style>
</head>
<body>
<nav class="lnb">
<ul>
<li class="on"><a href="#page01">春</a></li>
<li><a href="#page02">夏</a></li>
<li><a href="#page03">秋</a></li>
<li><a href="#page04">冬</a></li>
</ul>
</nav>
<div class="contents">
<section id="page01"><img src="./images/spring.jpg" alt="" /></section>
<section id="page02"><img src="./images/summer.jpg" alt="" /></section>
<section id="page03"><img src="./images/fall.jpg" alt="" /></section>
<section id="page04"><img src="./images/winter.jpg" alt="" /></section>
</div>
</body>
</html>