उदाहरण
scrollTop, scrollHeight और setInterval से ऑटो-स्क्रोलिंग कंटेनर बनाएं।
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
#scrollDemo { height: 300px; overflow-y: scroll; }
#scrollDataFeatures { height: 500px; background-color: skyblue; }
</style>
</head>
<body>
<div id="scrollDemo">
<div id="scrollDataFeatures"></div>
<h3>See the below Message and Scroll UP</h3>
</div>
<script>
var scrollData = document.getElementById("scrollDemo");
scrollData.scrollTop = scrollData.scrollHeight;
setInterval(() => {
var heading3Data = document.createElement("h3");
heading3Data.innerHTML = "Scroll Down...Please Scroll UP";
scrollData.appendChild(heading3Data);
scrollData.scrollTop = scrollData.scrollHeight;
}, 30 * 1000);
</script>
</body>
</html>
फ़ाइल सेव करें और Live Server से खोलें।
आउटपुट
हर 30 सेकंड में नया मैसेज जुड़ेगा और ऑटोमेटिकली नीचे स्क्रॉल होगा।