【发布时间】:2020-07-19 19:46:11
【问题描述】:
第一次在这里发帖,因为我对这个很绝望。
如此简单,但它确实.. 不.. 工作!
这里是:
一旦我滚动到某个点,我正在尝试向我的标题添加一个向下滑动的动画。 问题是过渡不起作用,它只是“跳跃”。
我忽略了什么?
我设置了这个 codepen 以尽可能简单地确定问题:https://codepen.io/MDVizzy/pen/yLeQRPM
HTML
<div class="wrapper">
<header>THIS REPRESENTS MY HEADER</header>
</div>
CSS
.wrapper {
height: 3000px; /* TO SIMULATE SCROLLBAR */
position: relative;
}
header {
background: red;
height: 100px;
width: 100%;
text-align: center;
line-height: 100px;
color: white;
position:fixed;
top: 0px;
animation: all 3s;
}
header.animation {
top: 200px;
}
JS
$( document ).ready(function() {
$(window).bind('scroll', function () {
if ($(window).scrollTop() > 300) {
$("header").addClass('animation');
} else {
$("header").removeClass('animation');
}
});
});
【问题讨论】:
-
使用过渡:全3s;不是动画。