【发布时间】:2018-03-16 18:03:37
【问题描述】:
我正在为一件简单的事情而苦苦挣扎。 当用户滚动超过 600 像素时,我尝试修复一个元素(手机 img),并在他在本节末尾时再次修复它。但是当他滚动回到顶部时,它并没有修复。为什么?我做错了什么?
一般来说,我会尝试在这款手机内部制作一些与滚动事件相关的过渡和动画,以及如何使用应用程序的某种教程。
这是我的问题的代码笔: https://codepen.io/anon/pen/YaGqRB?editors=1010 还有我丑陋的 JQuery:
$(window).scroll(function () {
if ($(window).scrollTop() > 584) {
$('.phone-container').addClass('phone-container-fixed');
}if ($(window).scrollTop() > 2201) {
$('.phone-container').removeClass('phone-container-fixed');
$('.phone-container').addClass('phone-container-fixed-bot');
}
});
css:
.phone-container{
position: relative;
top: 40px;
}
.phone-container-fixed{
position: fixed;
top: 50px;
}
.phone-container-fixed-bot{
position: absolute;
top: 2420px;
}
【问题讨论】:
标签: javascript jquery css scroll scrolltop