I am using a jQueryMobile (v1.4.0) collapsible set / accordions to display a list of elements and its content as shown in this jsFiddle.
<div id="List" data-role="collapsible-set">
<div data-role="collapsible" data-content-theme="c">
<h3>Lorem ipsum 1</h3>
<p>Suspendisse neque...</p>
</div>
<div data-role="collapsible" data-content-theme="c">
<h3>Lorem ipsum 2</h3>
<p>Lorem ipsum...</p>
</div>
</div>
The problem I have is with scrolling when the content of an item is longer than the length of the screen.
For instance in the fiddle:
=> the first item is closed and the second item is opened, but the page scrolling doesn't change and you now see the end of the second item's content.
Thus my question: Is there a smart way to force the page to set the "header" of the second item at the top of the screen?
Thanks, T.
Once a collapsible is expanded, retrieve its' .offset().top
and $.mobile.silentScroll()
to that position.
$(document).on("expand", "[data-role=collapsible]", function () {
var position = $(this).offset().top;
$.mobile.silentScroll(position);
});
Update: For jQuery Mobile 1.4, use collapsibleexpand
event.
Demo - jQM 1.0 - 1.1
Demo - jQM 1.2 - 1.3
Demo - jQM 1.4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With