2

I am using jQuery UI Accordion. One section has a scroll bar. I would like that scroll bar to default to the top every time that section is opened. Currently, it "remembers" its previous position. Is there a way to make it forget its position or always default to the top. I only want to set this for the particular section, not the entire page.

This post suggests using window.scrollTo(0, 0); to force the page to scroll to the top. But I'm unsure how to apply that to only a particular section.

Community
  • 1
  • 1
Ken
  • 3,091
  • 12
  • 42
  • 69

2 Answers2

1

You can set the scroll position of .ui-accordion-content to 0 at the accordion's change or changestart event.

Andy
  • 29,707
  • 9
  • 41
  • 58
  • Thank you. Would it be possible to provide an example? – Ken May 28 '11 at 22:38
  • Hm i tried it now but i can't reproduce your problem. It scrolls up automatically for me, maybe your markup is different or your jqUI version? Anyway i made an example of how it works: http://jsfiddle.net/8kgjG/1/ (i set the scrollTop to 50 here) – Andy May 29 '11 at 08:30
  • When I first opened the section, the scroll position would be at the top, but would always be located towards the bottom when I reopened the section. In any case, your solution fixed the problem. Thank you! – Ken May 29 '11 at 15:48
  • Yes that's because i set the position only at the change event so it startet at the top, and at the event it's set to 50. Glad it helped! – Andy May 29 '11 at 15:54
0

set the scrollTop-property of the element to 0

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201