gpt4 book ai didi

javascript - 改变元素在 scroll() 上的位置

转载 作者:行者123 更新时间:2023-11-28 08:22:36 26 4
gpt4 key购买 nike

有以下 fiddle : http://jsfiddle.net/hpXL4/202/

试图让它工作,但似乎做不到?希望在滚动 X 高度后基本上改变元素的位置。

var cta = $("#bottomcta");
cta.on("scroll", function(e) {
if (this.scrollTop > 50) {
cta.addClass("fixed");
}
else {
cta.removeClass("fixed");
}
});

最佳答案

必须使用 Windows 元素。下面的代表性链接.... :)

Link

var cta = $(window);
cta.on("scroll", function(e) {
if (cta.scrollTop() > 50) {
$("#bottomcta").addClass("fixed");
}
else {
$("#bottomcta").removeClass("fixed");
}
});

关于javascript - 改变元素在 scroll() 上的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685453/

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