Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
jQuery Mobile collapsible sets. Move content to the top
/**
* Attach a handler to collapsible sets.
*
* Attach a handler to every collapsible (filtered by their jQM’s role) so that,
* every time a collapsible’s header is tapped, it will scroll to the top of the page (both header and content)..
*
* @link https://imelgrat.me/javascript/collapsible-scroll-jquery-mobile/
*/
$(document).on('pagebeforeshow', function()
{
$("[data-role='collapsible']").collapsible(
{
collapse: function(event, ui)
{
$(this).children().next().slideUp(350);
},
expand: function(event, ui)
{
$(this).children().next().slideDown(500);
jQuery('html, body').animate(
{
scrollTop: jQuery(this).offset().top - 10
}, 500);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.