【问题标题】:Animated header dissappers while scrolling upwards向上滚动时动画标题消失
【发布时间】:2015-05-06 05:30:13
【问题描述】:

我创建了一个在页面加载时向下滑动的动画标题 div 菜单。我使用动画延迟将动画延迟 1 秒。当用户向下滚动时,标题 div 会很好地改变颜色,但是当向上滚动时,标题会消失一瞬间。请帮忙。

$(window).scroll(function() {
            if ($(this).scrollTop() > 250){
                $('header').addClass("sticky");
                    $('a').css({
                        color: '#fff'
                    });
                }
                else{
                    $('header').removeClass("sticky");
                    $('a').css({
                        color: '#151515'
                    });

                }
        });
body{
    margin:0px;
}
#content{
    height:500px;
    width:500px;
    display:block;
    background-color:pink;
    margin: 0 auto;
    margin-top:50px;
}
header{
    position: fixed;
    top: -300px;
    width: 100%;
    height:50px;
    padding-top:25px;
    text-align: center;
    background: red;
    z-index: 1;
    font-size: .8em;
    
    -webkit-transition: all 0.4s ease;
    -moz-transition: all 0.4s ease;
    transition: all 0.4s ease;
    

    animation:theheader 1s;
    -moz-animation:top theheader 1s; /* Firefox */
    -webkit-animation:theheader 1s; /* Safari and Chrome */

    -webkit-animation-delay:  1s; /* Chrome, Safari, Opera */
    animation-delay:  1s;
    
     animation-fill-mode: forwards;
    -webkit-animation-fill-mode: forwards;




}
header.sticky {
    height:50px;
    padding-top:25px;
    background-color: blue;
    color: #FFF;
    
}
@-moz-keyframes theheader
{
    from {
        top: -300px;
    }
    to {
        top:0px;
    }
}
<header>
    MENU
</header>
<div id="content">
</div>
<div id="content">
</div>
<div id="content">
</div>

https://jsfiddle.net/qectrqg3/35/

【问题讨论】:

    标签: javascript jquery css


    【解决方案1】:

    如果您只是简单地为顶部值设置动画,我建议您使用过渡而不是动画。过渡将确保您在过渡期间更改“动画”值时不会出现闪烁。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-17
      • 2021-10-03
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多