javascript - Fade images after delay -
i'm trying switch images in div every few seconds
current code works, there 2 things want change , need that:
- the div resizes current image displaying in it, want use size of bigger image
- i want fade between images instead of switching
thanks reading, hope can me.
this got far:
var imgindex = 0; setinterval(function() { images[imgindex].style.display = "none"; imgindex++; if (imgindex >= images.length) { imgindex = 0; } images[imgindex].style.display = "block"; }, 5000);
.imagedisplay { display: inline-block; width: 100%; background-color: white; color: black; border-radius: 5%; margin: 2px; padding: 1px; opacity: 0.5; transition-duration: 0.5s; } .imagedisplay:hover { opacity: 1; } .image { width: 99%; height: auto; margin: 1px; padding: 1px; border-radius: 5%; cursor: pointer; display: none; }
<div class="imagedisplay"> <p>description</p> <img class="image"></img> <img class="image"></img> </div>
firstly set div equal size of large image , use:
object-fit: cover; object-position:center;
as switching use:
transition: opacity .3s linear;
read here on how implement transitions. suggestion stacking them , fading them in 1 one every few seconds.
Comments
Post a Comment