gpt4 book ai didi

jquery - 滚动到浏览器顶部时如何将 div 设置为位置 :fixed,?

转载 作者:太空宇宙 更新时间:2023-11-04 03:30:48 25 4
gpt4 key购买 nike

我希望我能描述我的问题:

我的页面上有一个购物篮 div,其标题( Logo 、topnav)下方包含价格信息。当向下滚动页面时,我希望购物篮 div 停止滚动(位置:固定),当它触及浏览器的上端时...

有人知道我要找的东西的关键字吗?

谢谢

一月

最佳答案

假设您有 jQuery 并且您的购物篮有类“购物车”

$(document).on('scroll', function(){
if($(document).scrollTop() >= $('.cart').offset().top){
// Add position:fixed styling (eg. with a specific class)
} else {
// Remove position:fixed styling
}
});

关于jquery - 滚动到浏览器顶部时如何将 div 设置为位置 :fixed,?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26338492/

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