首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSS动画,只改变图像,没有动画

CSS动画,只改变图像,没有动画
EN

Stack Overflow用户
提问于 2021-10-08 08:33:27
回答 2查看 35关注 0票数 0

我试着用像动画一样的淡入淡出来改变照片,但它们只是在它们之间切换,

你知道如何修复它,或者我做错了什么吗?提前谢谢你。

CSS:.slider{

代码语言:javascript
复制
width: 300px;
height: 400px;
background: url("images/flip1.png");
background-repeat: no-repeat;
background-size: 300px 300px;
animation: slide 20s ease-in-out;

}

@关键帧幻灯片{ 25%{

代码语言:javascript
复制
    background: url("images/flip2.png");
    background-size: 300px 300px;
    background-repeat: no-repeat;
}
50%{
    
    background: url("images/flip3.png");
    background-size: 300px 300px;
    background-repeat: no-repeat;
}
75%{
    background: url("images/flip4.png");
    background-size: 300px 300px;
    background-repeat: no-repeat;
}
100%{
    background: url("images/flip1.png");
    background-size: 300px 300px;
    background-repeat: no-repeat;
}

}

html:

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-08 08:47:23

我想这对你有帮助。

代码语言:javascript
复制
.slide-container {
    position: relative;
}

.slide1 {
    width: 300px;
    height: 400px;
    background: red url("images/flip1.png");
    background-repeat: no-repeat;
    background-size: 300px 300px;
    animation: slide1 20s ease-in-out;
    position: relative;
}

.slide2 {
    width: 300px;
    height: 400px;
    background: blue url("images/flip2.png");
    background-repeat: no-repeat;
    background-size: 300px 300px;
    animation: slide2 20s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.slide3 {
    width: 300px;
    height: 400px;
    background: green url("images/flip3.png");
    background-repeat: no-repeat;
    background-size: 300px 300px;
    animation: slide3 20s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.slide4 {
    width: 300px;
    height: 400px;
    background: yellow url("images/flip4.png");
    background-repeat: no-repeat;
    background-size: 300px 300px;
    animation: slide4 20s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

@keyframes slide1 {
    0% {
        opacity: 1;
    }
    20% {
        opacity: 1;
    }
    25% {
        opacity: 0;
    }
    95% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@keyframes slide2 {
    0% {
        opacity: 0;
    }
    20% {
        opacity: 0;
    }
    25% {
        opacity: 1;
    }
    45% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
    100% {
        opacity: 0;
    }
}

@keyframes slide3 {
    0% {
        opacity: 0;
    }
    45% {
        opacity: 0;
    }
    50% {
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    75% {
        opacity: 0;
    }
    100% {
        opacity: 0;
    }
}

@keyframes slide4 {
    0% {
        opacity: 0;
    }
    70% {
        opacity: 0;
    }
    75% {
        opacity: 1;
    }
    95% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}
代码语言:javascript
复制
<div class="slide-container">
    <div class="slide1"></div>
    <div class="slide2"></div>
    <div class="slide3"></div>
    <div class="slide4"></div>
</div>

票数 1
EN

Stack Overflow用户

发布于 2021-10-08 08:35:17

对其他浏览器使用前缀

代码语言:javascript
复制
 -webkit-animation: 4s linear 0s infinite alternate move_eye;
     -moz-animation: 4s linear 0s infinite alternate move_eye;
       -o-animation: 4s linear 0s infinite alternate move_eye;
          animation: 4s linear 0s infinite alternate move_eye;

https://developer.mozilla.org/ru/docs/Web/CSS/animation

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69492853

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档