我有一个标题,当用户滚动到页面上的第一部分时,我想淡入。我使用不透明度为 0 的 div 更改为不透明度 1,如下所示:
$(window).scroll(function () {
// If the scroll position is past the 1st section...
if ($('body').scrollTop() > 500) {
$('#ribbon').css('opacity', 1);
} else {
$('#ribbon').css('opacity', 0);
}
});
这很好用,但是当我尝试使用fadeIn()
or为不透明度设置动画时animate()
,它会停止工作并且不会在 div 中淡入淡出。