How to reset persistent scrollbar position after div refresh in FF3?

22,412

Solution 1

OK, after contemplating David M's suggestions, I figured it out. Since #interiors is a child of #content it was also being hidden. So I had to show it first, set scrollLeft then hide it again. A bit kludgy, but whatever works...

$('#landing, #interiors, #caption').empty();
$('#content').show()
$('#interiors').scrollLeft(0);
$('#interiors, #caption').hide();

Regarding the cached data in FF3, I'm still not clear on that. Save that one for a rainy day...

Thanks

Solution 2

Just for reference, here is a relevant Firefox bug:

https://bugzilla.mozilla.org/show_bug.cgi?id=706792

Share:
22,412
rcon
Author by

rcon

Updated on September 23, 2020

Comments

  • rcon
    rcon over 3 years

    I'm experiencing a weird scrollbar issue. I'm building a page that uses jQuery and PHP to dynamically load images into a DIV sequentially. This DIV is a fixed height but uses a scrollbar for its variable width. The problem is that the scrollbar does not reset after a dynamic refresh of the DIV. So when the user scrolls and then refreshes with new content, the scroll bar position stays persistent instead of resetting back to the left.

    This seems to only happen in FF3. The scrollbar resets perfectly fine in Chrome, Safari, and IE8.

    For each refresh, the DIV is hidden, emptied, sized with CSS, then sequentially appended with images.

    I've tried resetting white-space: normal before the nowrap, playing around with overflow, and also jQuery's scrollLeft to no avail. It still behaves strangely in FF3, and only FF3.

    Click a thumbnail, move the scrollbar then click another thumb.

    Thanks for any help!

  • rcon
    rcon about 14 years
    I did more analysing in Firebug. Whats happening is that upon DIV refresh, the scrollLeft value resets to zero until it needs a scrollbar. If the scrollbar is needed, it restores the previous value (you'll see it toggle). If the scrollbar isn't needed the value stays at zero, and subsequent refreshes will use this new stored value of zero whether or not a scrollbar is needed. Now I want to figure out a way to zero or block the old value.
  • cryo
    cryo about 14 years
    @rcon: I've added some more suggestions to reset the scrollbar, please reply if you're still having problems
  • rcon
    rcon about 14 years
    M: I thought doing a remove() would work too, but unfortunately it doesn't. One would think removing an element from the DOM would clear the persistent data. Its a good idea, so I'm going to try playing around with clone() next. Regarding the other suggestion, see my reply to Már Örlygsson's answer. Thanks for the ideas!
  • rcon
    rcon about 14 years
    @Davin M: Yes, you are absolutely correct. The element should be display: block. Your function works, but only as long as #content is not hidden. See my answer. Thanks for your help!
  • Zze
    Zze over 7 years
    Not just a relevant FF bug - the exact bug which is depicted in this question. +1