var myIndex = 0;
var lastIndex = null;
var slides;
window.onload = function()
{
slides = document.getElementsByClassName("mySlides");
slidePictures();
}
function slidePictures() {
slides[myIndex].style.display = "block";
slides[myIndex].className += " fadeIn";
console.log(slides[myIndex]);
setTimeout(function()
{
slides[myIndex].className = "mySlides";
console.log(slides[myIndex]);
setTimeout(function()
{
slides[myIndex].style.display = "none";
console.log("display none");
}, 1000);
}, 2000);
lastIndex = myIndex;
myIndex++;
if (myIndex >= 3)
return;
setTimeout(slidePictures, 4000);
}
.slidesDiv>img {
width: 80%;
height: 80%;
margin-left: 10%;
opacity: 0;
transition: opacity 1s;
}
.fadeIn {
opacity: 1 !important;
transition: opacity 1s;
}
<div class="slidesDiv">
<img class="mySlides" src="//placehold.it/200x80/0fb">
<img class="mySlides" src="//placehold.it/200x80/0bf">
<img class="mySlides" src="//placehold.it/200x80/fb0">
<img class="mySlides" src="//placehold.it/200x80/0fb">
<h1 id="indicator"> Indicator </h1>
</div>
所以我的問題是,圖像在第一時間變淡,但當時並沒有淡出之後,也不會消失?
這絕對是setTimeout
功能的問題,我想知道我在做什麼/假設不正確。
是的,那正是我想要的。最好刪除你的其他答案,並把它放在底部,而不是:) –