-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprob14.html
46 lines (39 loc) · 1.36 KB
/
prob14.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// The Window Scroller: You are developing a single-page application with a smooth scrolling effect. Implement a function named smoothScrollToTop that smoothly scrolls the window to the top when called.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smooth Scroll Example</title>
</head>
<body>
<div style="height: 2000px;"> <!-- Simulate a long page -->
<button id="scrollToTopButton" style="position: fixed; bottom: 20px; right: 20px;">Back to Top</button>
</div>
<script>
function smoothScrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}
// Attach event listener when document is ready
document.getElementById("scrollToTopButton").addEventListener("click", smoothScrollToTop);
</script>
</body>
</html>
<!--
<script>
if (typeof document !== "undefined") {
function smoothScrollToTop() {
window.scrollTo({
top: 0,
behavior: "smooth"
});
}
// Example for adding the button click listener (only runs in the browser)
document.getElementById("scrollToTopButton").addEventListener("click", smoothScrollToTop);
} else {
console.log("This script is not running in a browser.");
}
</script> -->