gpt4 book ai didi

JavaScript SlideShow - 淡入淡出效果

转载 作者:行者123 更新时间:2023-11-27 23:10:53 25 4
gpt4 key购买 nike

我有一个 JavaScript SlideShow,我想在图像更改时删除“闪光”效果,并添加淡入淡出效果。我找到了很多解决方案,但没有任何效果我不知道为什么 :-( ...

我把我的代码贴在这里: http://jsfiddle.net/nanoupi42/xu06jdb2/1/

HTML:

<div class="slideshow-container hidden__M__Device">

<div class="mySlides fades">

<img src="http://images7.alphacoders.com/338/338687.jpg" class="img-fluid" alt="">

</div>

<div class="mySlides fades">

<img src="https://www.usine-digitale.fr/mediatheque/9/3/5/000729539/viveport-infinity.jpg" class="img-fluid" alt="">

</div>

<div class="mySlides fades">

<img src="https://www.philosophytalk.org/sites/default/files/o-INFINITY-facebook.jpg" class="img-fluid" alt="">

</div>

</div>

<div class="dots_container hidden__M__Device">

<span class="dot" onclick="currentSlide(1)"></span>

<span class="dot" onclick="currentSlide(2)"></span>

<span class="dot" onclick="currentSlide(3)"></span>

</div>

CSS:

.slideshow-container {
max-width: 100%;
width: 100%;
position: absolute;
height: 1082px;
z-index: -1;
}

.mySlides{
display: none;
}

.mySlides > img {
background-repeat: no-repeat;
width: 100%;
position: relative;
z-index: -1;
/* top:-154px; */
}

.dots_container{
position: absolute;
margin-top: 230px;
display: flex;
flex-direction: column;
margin-left: 81.5%;
}

.dot {
position: relative;
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: red;
border-radius: 50%;
display: inline-block;
margin-top: 5px;
transition: background-color 0.6s ease;
}

.active, .dot:hover {
background-color: rgba(255,255,255,0.5);
}

.fades {
-webkit-animation-name: fades;
-webkit-animation-duration: 1.5s;
animation-name: fades;
animation-duration: 1.5s;
}

@-webkit-keyframes fades {
from {opacity: .4}
to {opacity: 1}
}

@keyframes fades {
from {opacity: .4}
to {opacity: 1}
}

JavaScript:

var slideIndex = 1;
showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}

// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}

function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {slideIndex = 1}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
}
setInterval(plusSlides, 2000, 1); // call plusSlider, with 1 as parameter

如您所见,图片更改时会出现一种“闪光”效果。我想删除它并像这样添加交叉淡化效果 https://cobwwweb.com/simple-looping-crossfade-image-slideshow .你知道我该怎么做吗?

非常感谢。

那欧

最佳答案

查看 fades 类上的 css 动画。关键帧与 opacity 一起使用,您可以将它们更改为与 transform 属性上的 translateX 一起使用。

@keyframes fades {
from {transform: translateX(-100%)}
to {transform: translateX(0%)}
}

如果您需要动画方面的帮助,请联系 animate.css或 ofc 所有关于 css 动画属性的文档。

关于JavaScript SlideShow - 淡入淡出效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58526845/

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