gpt4 book ai didi

jquery-mobile - jQuery 移动 : Make the header hide on scroll down and show on scroll up

转载 作者:行者123 更新时间:2023-12-04 06:28:54 27 4
gpt4 key购买 nike

我们在许多移动应用程序中看到的一个常见现象是,当用户向下滚动页面时,标题会消失,而当用户向上滚动页面时,标题会出现。我们如何在 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;
});

关于jquery-mobile - jQuery 移动 : Make the header hide on scroll down and show on scroll up,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21249276/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com