คุณสมบัติ scroll-behavior ใช้เพื่อกำหนดลักษณะการทำงานของ scroll เราสามารถตั้งค่าคุณสมบัติที่แตกต่างกันดังต่อไปนี้สำหรับคุณสมบัติการเลื่อน -
scroll-behavior: auto|smooth|initial|inherit;
ตัวอย่าง
ให้เรามาดูตัวอย่างการใช้งานคุณสมบัติพฤติกรรมการเลื่อน -
<!DOCTYPE html>
<html>
<head>
<style>
html {
scroll-behavior: smooth;
}
#area1 {
height: 400px;
background-color: red;
}
#area2 {
height: 600px;
background-color: orange;
}
#area3 {
height: 550px;
background-color: magenta;
}
</style>
</head>
<body>
<h1>Demo Heading</h1>
<div class="main" id="area1">
<h2>Section 1</h2>
<a href="#area2">Reach Section 2</a>
</div>
<div class="main" id="area2">
<h2>Section 2</h2>
<a href="#area3">Reach Section 3</a>
</div>
<div class="main" id="area3">
<h2>Section 3</h2>
<a href="#area1">Reach Section 1</a>
</div>
</body>
</html> ผลลัพธ์

ตอนนี้ คลิก “เข้าถึงส่วนที่ 2” –

ตอนนี้ คลิก “ถึงส่วนที่ 3” เพื่อเลื่อนไปยังส่วนที่ 3 อย่างราบรื่น -
