0

I built a long page website, so I decide to build a sidebar to navigate user. I want to know which part my user is viewing, so I can change the sidebar css to active or hightlight.

Is there any js or jquery function I can use to get which part user is viewing?

2 Answers2

0

There are some jquery plugins you can use, Ex: Waypoints, Jquery Inview . Using this plugin you can change the class name for sidebar when the user scrolls into some part of the page or section. Simple solution is using $(window).scrollTop()

     $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            //change the class name for sidebar         
                    } else {
            //revert the class name for sidebar
        }
    });
Gajanan
  • 140
  • 1
  • 14
  • Thank you for your help. But my page is dynamic, the position of each content is variable. Can u help with that? – user3467010 Mar 27 '14 at 16:33
0

I get my solution through This Question.

I can calculate the pixel from the top to the current viewpoint, and then find out the first element's id.

Thank for your help again!

Community
  • 1
  • 1