有以下 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 元素。下面的代表性链接.... :)
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/