首页 > 解决方案 > 背景放大动画

问题描述

我正在尝试在特定秒内放大背景图像的动画。它正在发生,但它再次重置。

我在 jsfiddle 中创建了示例链接: https ://jsfiddle.net/onlinesolution/tk6rcLdx/

我在这里想念什么?

body:before{
  content:"";
  position:absolute;
  top:0px;
  left:0px;
  height: 100vh;
   width: 100%;
    background-image: url("http://paulmason.name/media/demos/full-screen-background-image/background.jpg");
    background-position:center center;
    background-size: 100% 100%;
    background-repeat: no-repeat;
     z-index: -9;
    -webkit-animation: zoomin 5s ease-in;
    animation: zoomin 5s ease-in;
        }

/* Zoom in Keyframes */
@-webkit-keyframes zoomin {
  0% {transform: scale(1);}
  100% {transform: scale(1.5);}
}
@keyframes zoomin {
  0% {transform: scale(1);}
  100% {transform: scale(1.5);}
} /*End of Zoom in Keyframes */

标签: csscss-transitionscss-animations

解决方案


您缺少一个简单的属性:animation-fill-mode: forwards

这是添加了该属性的代码,您会看到效果很好

https://codepen.io/manAbl/pen/vjbgYK

进一步阅读:

https://devdocs.io/css/animation-fill-mode


推荐阅读