highlight menu item when scrolling down to section

对于css

1
2
3
html {
scroll-behavior: smooth;
}

用id + hash的方式滚动

对于js

事件:

1
window.addEventListener('scroll', callback);

throttle + js判断后 再增删 class

详细:下面30k viewed的页面

https://stackoverflow.com/questions/32395988/highlight-menu-item-when-scrolling-down-to-section