SunnyShah
SunnyShah

Reputation: 30517

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

How to get page 's scroll position change event?

I want to implement dynamic table of contents like http://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.

Upvotes: 0

Views: 547

Answers (1)

brymck
brymck

Reputation: 7663

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
}

Upvotes: 1

Related Questions