简体   繁体   中英

Change CSS based on scroll position/anchor points

On my site I'm currently having users click on a set of navigation links that will, onclick, highlight their backgrounds yellow.

I remember seeing a similar effect on this site at http://docs.meteor.com/

Here, when user scrolls to a specific anchor in the document, the navigation element that links to it is highlighted. How does this work? How do I begin to implement something like this on my page?

Any brief pieces of example code would be greatly appreciated. I've been working with some JavaScript for a while now and haven't been able to recreate anything.

EDIT: To clarify the effect I'm looking at on the Meteor site, when you scroll in the right column, the associated menu element on the left column changes font color to red. NOT, the on hover effect.

在bootstrap中有一个名为scrollspy的现成品

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM