Search code examples
javascriptjqueryscrollhorizontalscrollview

How to calculate horizontal scrolling position


I have made a horizontal scrolling website. The main problem is that I am not able to highlight the active menu item when loading for the first time or refreshing.

I also can't keep the active link permanently on home. Because if users will refresh the page while active on other page, the home page will get highlighted. My website is similar to this one: something like this website


Solution

  • If you're using jQuery, you can use .scrollLeft() to get the horizontal scroll of the page, in pixels.

    Like so:

    $(window).scroll(function() {
        var scroll = $('html, body').scrollLeft();
        // do stuff with the value...
    });