Tuesday, September 10, 2013

ScrollLeft() not working with Firefox

ScrollLeft() not working with Firefox

I have a jsfiddle here - http://jsfiddle.net/stevea/DyfGp/2/ - where an
outer box contains an inner box that extends out of the viewport. This
forces a horizontal scroll bar to appear.
A "Get Left Scroll" button reads the current left scroll and a "Set Left
Scroll to 20" button sets the left scroll to 20. This all works as I would
expect on Chrome and Safari: Initially selecting Get Left Scroll returns 0
because nothing is missing off the left end. If I maually move the scroll
bar some, selecting Get Left Scroll returns the amount I've scrolled,
because now this amount is missing off the left end. If is select "Set
Left Scroll to 20" the scroll moves 20 and 20px are now missing off the
left end. Excellent!
The problem is that none of this works in Firefox. In Firefox all the
scroll reads come back as 0 and writing a scroll doesn't seem to do
anything. Does anyone know what the problem might be?
Thanks
$('#getScroll').click(function() {
var bodyscroll = $('body').scrollLeft();
$('#scroll').html("left scroll is " + bodyscroll);
});
$('#setScroll').click(function() {
$('body').scrollLeft(20);
var bodyscroll = $('body').scrollLeft();
$('#scroll').html("left scroll is " + bodyscroll);
});

No comments:

Post a Comment