gpt4 book ai didi

jquery - 向下滚动时显示搜索栏,滚动回顶部时隐藏搜索栏

转载 作者:行者123 更新时间:2023-12-01 04:47:24 25 4
gpt4 key购买 nike

当页面向下滚动时,我需要在顶部显示粘性搜索栏。登陆页面已经包含一个搜索框。因此,粘性栏只应在其不在 View 中时出现,而当搜索框返回查看时,粘性搜索栏应关闭。我如何使用 jquery 来做到这一点?

最佳答案

正如 Stemie 所说,如果你看起来尝试过,你会得到更多答案,但无论如何,它就是这样。看看这个fiddle完整的例子。下次试试,贴出相关代码

jQuery

var searchHeight = $(".search-bar").outerHeight();
var offset = $(".search-bar").offset().top;
var totalHeight = searchHeight + offset;

$(window).scroll(function(){
if($(document).scrollTop() >= totalHeight) {
$('.sticky-search').show();
} else {
$('.sticky-search').hide();
}
});

关于jquery - 向下滚动时显示搜索栏,滚动回顶部时隐藏搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27418166/

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