Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Last active February 15, 2019 12:26
Show Gist options
  • Save imelgrat/efc0e91e6e9178f1efb7bed4637d693c to your computer and use it in GitHub Desktop.
Save imelgrat/efc0e91e6e9178f1efb7bed4637d693c to your computer and use it in GitHub Desktop.
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