HTML Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> a{ margin: 10px; } div > p{ line-height: 3; font-size: 45px; text-align: center; } div{ height:150px; width: 150px; border: 1px solid black; overflow-y: scroll; } </style> </head> <body> <h1>CSS scroll-behavior Property</h1> <a href="#my1">1</a><a href="#my2">2</a><a href="#my3">3</a> <div> <p id="my1">1</p> <p id="my2">2</p> <p id="my3">3</p> </div> <button onclick="myFunction()">Click Me</button> <script> var x = document.getElementsByTagName("div")[0]; function myFunction(){ x.style.scrollBehavior = "smooth"; } </script> <p><strong>Note</strong>: click on the button to change the 'scroll-behavior' from auto to scroll.</p> </body> </html>
OUTPUT
×

Save as Private