An element with scrollLeft scrolls faster than the rest of the document

I have an element that has a fixed position, but has the ability to scroll left and right using the jQuery calculation that I used from this example in JsFiddle.

$(window).scroll(function(event) {
var x = 0 - $(this).scrollLeft();
var y = $(this).scrollTop();

// whether that below the form
if (y >= top) {
    // if so, ad the fixed class
    $('.scroll_fixed').addClass('fixed');
} else {
    // otherwise remove it
    $('.scroll_fixed').removeClass('fixed');
}

$(".scroll_fixed").offset({
    left: x + leftInit
});

});

The solution works well until I have to scroll left, where the element scrolls "parallaxes" against the rest of the document - i.e. it scrolls about twice as fast as the rest of the document.

I know this is a problem with jQuery calculation, but was it interesting if someone came across this before? and if so, how did you deal with this? I am at a loss ....

change

- , $(window).scrollLeft(); , .

div "wrapperDiv", $( ". wrapperDiv" ). scrollLeft();

, , Stack Overflow, 7 ....

+5
1

, :

" , $(window).scrollLeft(); , . wrapper " wrapperDiv ", $(".wrapperDiv").scrollLeft();"

0

All Articles