bbarakaci / fixto

A jQuery plugin for sticky positioning
MIT License
217 stars 57 forks source link

Incorrect "left" value when window width is less than document width #50

Open danielbachhuber opened 7 years ago

danielbachhuber commented 7 years ago

When the window width is less than the document with, left: N px is calculated incorrectly. The result of this bug is that the scrolling element jumps out of its rails when the user scrolls horizontally.

Here's a GIF to visually describe the issue:

fixto-lateralscroll

I was able to fix this issue with [snip]:

sidebarSectionTop.fixTo('.sidebar-section-top-track', options);
sidebarSectionMiddle.fixTo('.sidebar-section-middle-track', options);

var lastScrollLeft = 0;
// Redraw sticky sidebar when scrolling laterally on constrained viewports
// fixTo ends up with an incorrect "left: N; position: fixed", and needs
// to be recalculated
$(window).scroll(function(){
    // If the document is less than or equal to window, no side scroll
    if ( $(document).width() <= $(window).width() ) {
        return;
    }
    var documentScrollLeft = $(document).scrollLeft();
    if ( lastScrollLeft != documentScrollLeft ) {
        lastScrollLeft = documentScrollLeft;
        sidebarSectionTop.fixTo('refresh');
        sidebarSectionMiddle.fixTo('refresh');
    }
});

12 might be the same issue. Not sure whether I expect this to be supported by the library directly, but I thought it'd be worthwhile to report.

bbarakaci commented 7 years ago

Yes it is #12

Thanks for taking time to report.