WeCodePixels / theia-sticky-sidebar

Glues your website's sidebars, making them permanently visible while scrolling.
MIT License
569 stars 209 forks source link

Sidebar doesn't take into account horizontal scrolling #13

Closed a1tus closed 7 years ago

a1tus commented 8 years ago

Hello.

Not sure if it was done on purpose but anyway... If we have sticky sidebar in fixed position (for example, left column with site nav) then after reducing window width below minimum to have horizontal scrollbar we get a bug: sidebar remains on its fixed position relative to viewport while we are scrolling right. While in my opinion more desirable default behaviour is to scroll out of viewport with the other content.

I've monkey-patched my local version so that sticky behave like I want but also decided to create an issue. Luckily it's a very little fix - we just need to add - $(window).scrollLeft() to the left property to get things done (by the way it's better to cache $window object also):

if (position == 'fixed') {
    o.stickySidebar.css({
        'position': 'fixed',
        'width': o.sidebar.width(),
        'top': top,
        'left': o.sidebar.offset().left + parseInt(o.sidebar.css('padding-left')) - $(window).scrollLeft()
    });
}

It can be turned on as an option for backward compatibility.

PS. Great lib, thanks for sharing!

liviucmg commented 7 years ago

Fixed in #30, can you please try it out and double-check if it's working properly now?