[英]Adding fade animation to my ready Slideshow
what im trying to do is to make my slideshow do some animation while changing photos, i have the very basic slide show我想要做的是让我的幻灯片在更改照片时做一些动画,我有非常基本的幻灯片
<div class="slider-wrapper">
<div class="slider-wrapper-item " style="background-image: url(/wp-content/themes/ETL/img/slider-image-1.jpg);"></div>
<div class="slider-wrapper-item" style="background-image: url(/wp-content/themes/ETL/img/slider-image-2.jpg);"></div>
<div class="slider-wrapper-item" style="background-image: url(/wp-content/themes/ETL/img/slider-image-3.jpg);"></div>
<div class="slider-wrapper-item" style="background-image: url(/wp-content/themes/ETL/img/slider-image-4.jpg);"></div>
<div class="slider-wrapper-item" style="background-image: url(/wp-content/themes/ETL/img/slider-image-5.jpg);"></div>
<div class="slider-play-icon"><img src="/wp-content/themes/ETL/img/play-arrow-grey.png"></div>
this is the js这是js
<script>
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("slider-wrapper-item");
console.log("slides",slides);
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 5000); // Change image every 2 seconds
}
</script>
i have found an article on how to make the fade animation but its complicated and i have no luck with it https://cobwwweb.com/simple-looping-crossfade-image-slideshow this is the exact animation i want.我找到了一篇关于如何制作淡入淡出动画的文章,但它很复杂,我没有运气https://cobwwweb.com/simple-looping-crossfade-image-slideshow这是我想要的确切动画。
if you want animation you can't use display none or block because display property does not support transition.
don't use this
slides[i].style.display = "none" and slides[slideIndex-1].style.display = "block";
instead of that make class for animation and add that class and remove whenever you want.
for example
.addAnimation{
// write your code here
}
.removeAnimation{
// write your code here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.