html - CSS webkit-动画滚动顶部

标签 html css scroll css-transitions

我的 CSS 不是很好。

跟随CSS不断滚动背景图片。

但我需要做的是滚动到顶部并停止背景图像的动画。你能帮我解决这个问题吗?

body {
     background-image: url(<?php echo get_template_directory_uri().'/img /sas-sport-bg.jpg'; ?>);

    -webkit-animation:400s scroll  linear;
    -moz-animation:400s scroll  linear;
    -o-animation:400s scroll  linear;
    -ms-animation:400s scroll  linear;
    animation:400s scroll  linear;
}
 @-webkit-keyframes scroll{
    0%{
        background-position:0px 0px;
    }
}
@-moz-keyframes scroll{
    20%{
        background-position:0px -1000px;
    }
}
@-o-keyframes scroll{
    40%{
        background-position:0px -1000px;
    }
}
@-ms-keyframes scroll{
    80%{
        background-position:0px -1000px;
    }
}
@keyframes scroll{
    100%{
        background-position:0px -1000px;
    }
}

最佳答案

您可以在动画中将 animation-fill-mode 设置为 forwards 以在最后一个状态停止动画。

检查下面的代码:

body {
         background-image: url(<?php echo get_template_directory_uri().'/img /sas-sport-bg.jpg'; ?>);

        -webkit-animation:400s scroll  linear forwards;
        -moz-animation:400s scroll  linear forwards;
        -o-animation:400s scroll  linear forwards;
        -ms-animation:400s scroll  linear forwards;
        animation:400s scroll  linear forwards;
    }
     @-webkit-keyframes scroll{
        100%{
            background-position:0px -1000px;
        }
    }
    @-moz-keyframes scroll{
        100%{
            background-position:0px -1000px;
        }
    }
    @-o-keyframes scroll{
        100%{
            background-position:0px -1000px;
        }
    }
    @-ms-keyframes scroll{
        100%{
            background-position:0px -1000px;
        }
    }
    @keyframes scroll{
        100%{
            background-position:0px -1000px;
        }
    }

关于html - CSS webkit-动画滚动顶部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46757336/

相关文章:

html - 如何在固定标题的中心将 2 个 Logo 彼此叠加(叠加)...为滚动动画效果做准备

jquery - 如何使此滚动功能在jQuery上起作用?

javascript - 滚动时淡出页面顶部和底部的文本(使用 jQuery)

jquery - 单击链接后需要隐藏/滑动 div

javascript - 点击 scoll 到顶部

javascript - 在没有 JQuery 的情况下使用响应式图像映射

css - 带 CSS 的背景幻灯片(全屏+响应式)

html - 如何使用 css 重新定位具有线性渐变的图像?

html - IE 在菜单子(monad)项上创建不必要的偏移量

jquery 滚动到特定的 div 位置以防出现错误和焦点