html,body{
/* 核心屬性 讓頁(yè)面平滑滾動(dòng)*/
scroll-behavior: smooth;
}
如果頁(yè)面中用到了點(diǎn)擊錨點(diǎn)跳轉(zhuǎn)到對(duì)應(yīng)的位置,只需要加上上面這個(gè)樣式即可實(shí)現(xiàn)平滑滾動(dòng)到指定位置。利用它不需要js就可以實(shí)現(xiàn)頁(yè)面置頂?shù)男Ч?,很?shí)用。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
html,body{
/* 核心屬性 讓頁(yè)面平滑滾動(dòng)*/
scroll-behavior: smooth;
}
#one,#two,#three{
width: 80%;
height: 700px;
background-color: #eee;
margin: 50px auto;
font-size: 50px;
text-align: center;
line-height: 700px;
}
/* 定位置頂按鈕 */
.dTop{
position: fixed;
right: 20px;
bottom: 100px;
background-color: red;
text-align: center;
line-height: 60px;
width: 60px;
}
.rightNav{
position: fixed;
right: 20px;
bottom: 200px;
}
a{
display: block;
text-align: center;
line-height: 60px;
width: 60px;
color: aliceblue;
text-decoration: none;
margin-bottom: 10px;
background-color: skyblue;
}
</style>
</head>
<body>
<section id="one">模塊1</section>
<section id="two">模塊2</section>
<section id="three">模塊3</section>
<div class="rightNav">
<a href="#one">01</a>
<a href="#two">02</a>
<a href="#three">03</a>
</div>
<a href="#one" class="dTop">
置頂
</a>
</body>
</html>
該文章在 2024/7/9 15:47:57 編輯過(guò)