Last active
February 15, 2019 12:26
-
-
Save imelgrat/efc0e91e6e9178f1efb7bed4637d693c to your computer and use it in GitHub Desktop.
jQuery Mobile collapsible sets. Move content to the top
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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