gpt4 book ai didi

css3 图像淡入淡出(无 javascript)

转载 作者:技术小花猫 更新时间:2023-10-29 11:47:59 26 4
gpt4 key购买 nike

我很确定可以使用新的 css 动画功能进行纯 css 图像交叉淡入淡出。我的要求是它应该适用于没有 javascript 的任意数量的图像。

有人知道这是怎么做到的吗?

我是如何开始的:

img(src='img1.png')
img(src='img2.png')
img(src='img3.png')
img(src='img4.png')

接下来所有的图像都被设置为堆叠在一起,第一个显示:

img
opacity 0
transition 1s
position absolute

&:first-child
opacity 100

现在我该如何浏览每张图片?

编辑:似乎不可能。需要 javascript。

最佳答案

这篇文章是我见过的做这种效果最好的文章。

http://tympanus.net/codrops/2012/01/02/fullscreen-background-image-slideshow-with-css3/

他们使用跨度、动画和 :nth-child 属性来实现背景图像之间的淡入淡出。非常棒。

.cb-slideshow li span {
width: 100%;
height: 100%;
position: absolute;
top: 0px;
left: 0px;
color: transparent;
background-size: cover;
background-position: 50% 50%;
background-repeat: none;
opacity: 0;
z-index: 0;
animation: imageAnimation 36s linear infinite 0s;
}


.cb-slideshow li:nth-child(1) span {
background-image: url(../images/1.jpg)
}
.cb-slideshow li:nth-child(2) span {
background-image: url(../images/2.jpg);
animation-delay: 6s;
}
.cb-slideshow li:nth-child(3) span {
background-image: url(../images/3.jpg);
animation-delay: 12s;
}
.cb-slideshow li:nth-child(4) span {
background-image: url(../images/4.jpg);
animation-delay: 18s;
}
.cb-slideshow li:nth-child(5) span {
background-image: url(../images/5.jpg);
animation-delay: 24s;
}
.cb-slideshow li:nth-child(6) span {
background-image: url(../images/6.jpg);
animation-delay: 30s;
}

.cb-slideshow li:nth-child(2) div {
animation-delay: 6s;
}
.cb-slideshow li:nth-child(3) div {
animation-delay: 12s;
}
.cb-slideshow li:nth-child(4) div {
animation-delay: 18s;
}
.cb-slideshow li:nth-child(5) div {
animation-delay: 24s;
}
.cb-slideshow li:nth-child(6) div {
animation-delay: 30s;
}

关于css3 图像淡入淡出(无 javascript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8540906/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com