我们在许多移动应用程序中看到的一个常见问题是当用户向下滚动页面时标题消失,当它们向上滚动页面时,标题会出现.我们如何在jQuery Mobile中实现这一目标? (我在下面回答我自己的问
/**
* Header scroll control
* When the user scrolls down the page hide the header, when they scroll up show it.
*/
var lastScrollPosition;
$(document).scroll( function() {
var scrollPosition = $(this).scrollTop();
// Scrolling down
if (scrollPosition > lastScrollPosition){
// If the header is currently showing
if (!$('[data-role=header].ui-fixed-hidden').length) {
$('[data-role=header]').toolbar('hide');
}
}
// Scrolling up
else {
// If the header is currently hidden
if ($('[data-role=header].ui-fixed-hidden').length) {
$('[data-role=header]').toolbar('show');
}
}
lastScrollPosition = scrollPosition;
});
