How it works
- Fixed bottom: CSS keeps the button stuck to the bottom via
position: fixed; bottom: 18px;. - Follow mouse X: JS listens to
mousemoveand setsstyle.leftto track the cursor, clamped inside the viewport. - Appear on scroll: When you scroll past 300px, the button gets a
.showclass to fade in. - Smooth scroll to top: Clicking the button runs
window.scrollTo({ top: 0, behavior: 'smooth' }).
Demo content
Below is spacer content to enable scrolling.
End of content. Try the button!