I'm designing a very simple web page(HTML only), the only "feature" I want to implement is to do something when the user scrolls down the page, is there a way to capture that "event" somehow?
相关问题
- Views base64 encoded blob in HTML with PHP
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
You can't do it with just HTML, you'll need to use Javascript. I recommend using jQuery, so your solution can look like this:
If you don't want or are unable to use jQuery, you can use the
onscroll
solution posted by Anthony.This works for me.
A better way is to not only check for scroll events but also for direction scrolling like below;
u can simply use this
If you don't want to use jQuery (which you might not do for a very simple HTML page), you can accomplish this using regular Javascript:
You mentioned that you wanted to do something when they scroll down the page - the onscroll event fires off scrolling in any direction, in either the x- or y-axis, so your function will be called any time they scroll.
If you really want it to only run your code when they scrolled down the page, you'd need to preserve the previous scroll position to compare against whenever onscroll gets called.
Just for completeness, there's another solution using another JS framework (Mootools)