javascript - How to get the dom element at the top of the current page in js.
黄舟
黄舟 2017-05-19 10:29:38
0
2
662

Mainly I want to achieve an effect similar to the right navigation bar of Baidu Encyclopedia. As the page scrolls, the navigation bar on the right also changes. Thanks.

http://baike.baidu.com/item/G...

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
滿天的星座

Listen to the window.onscroll event. When scrolling, dynamically determine the current scrolling distance. The code is roughly as follows:

window.onscroll = function(){
    var height = document.documentElement.scrollTop + document.body.scrollTop;
    if(height >= '目录锚点高度'){
        //TODO 给当前锚点加高亮class,并且去掉其他高亮的锚点的样式
    }
}
给我你的怀抱

I don’t know if this is a similar effect you want? A small demo written by myself

    https://jsfiddle.net/f59e8enj/
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template