开发者

How to get page 's scroll position change event in JS?

开发者 https://www.devze.com 2023-03-15 18:54 出处:网络
How to get page \'s scroll position change event? I want to implement dynamic table of contents like http:开发者_StackOverflow中文版//bonsaiden.github.com/JavaScript-Garden/ ( In this website, with y

How to get page 's scroll position change event?

I want to implement dynamic table of contents like http:开发者_StackOverflow中文版//bonsaiden.github.com/JavaScript-Garden/ ( In this website, with your scrolling of the webpage, It also shows the current active item)

Is it possible to implement same thing without getting current scroll-position?

I am very new to JS and web-world.


That page does use some JS trickery with its <nav> element, but it's fixing the location of the sidebar using position: fixed, that is, using CSS not JavaScript. Here's the relevant style declaration (comments mine):

nav {
  position: fixed;    // fix position
  margin-left: 750px; // add 750 px of room to the left
  top: 0;             // set 0px from top of page
}
0

精彩评论

暂无评论...
验证码 换一张
取 消