5

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

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

// whether that's 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 to the left, where the element being scrolled "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 the jQuery calculation, but was wondering if anybody has come across this before? and if so, how did you tackle it? I am at a bit of a loss....

edit

problem solved - It was because the code was using $(window).scrollLeft(); instead of the parent element within the scope of the element i was wishing to manipulate.

the wrapper div was classed as "wrapperDiv", so I used $(".wrapperDiv").scrollLeft();

I would mark this question as asked, but as I am new to Stack Overflow i cannot answer for a further 7 hours....

Olly Bradshaw
  • 83
  • 1
  • 4

1 Answers1

0

Just to flag this question as answered:

"It was because the code was using $(window).scrollLeft(); instead of the parent element within the scope of the element i was wishing to manipulate. The wrapper div was classed as "wrapperDiv", so I used $(".wrapperDiv").scrollLeft();"

David
  • 3,388
  • 2
  • 21
  • 25