I want to implement a scroll down menu on my website.
On pages that are taller than the browser window height, I can test the scroll position with window.pageYOffset
to decide if the menu should scroll down or not.
However, on pages that are shorter than the browser height, I cannot use the same method, since window.pageYOffset
is always 0
. Instead, I need to detect the direction of scroll. Can this be done?
Using a combination of:
window.pageYOffset
and window.innerHeight
You will be able to calculate how much of your menu is in view and which way to scroll.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.