I am trying to do an Ad banner (loop banner) with JavaScript. I want the first image to have fade and other no, seem it work with me but when second loop start (and next ones) the first image loose its fade effect. What's wrong with my code?
function displayAd2() {
setTimeout(() => {
element = document.querySelector("#ad_container2");
element.style.backgroundImage = "http://via.placeholder.com/150)";
element.style.opacity = "1";
element.style.transition = "2s ease-in-out";
setTimeout(() => {
element = document.querySelector("#ad_container2");
element.style.backgroundImage = "http://via.placeholder.com/150";
element.style.opacity = "1";
element.style.transition = "0s ease-in-out";
setTimeout(() => {
element = document.querySelector("#ad_container2");
element.style.backgroundImage = "http://via.placeholder.com/150";
element.style.opacity = "1";
element.style.transition = "0s ease-in-out";
setTimeout(() => {
displayAd2();
}, 2500);
}, 2000);
}, 100);
}, 100);
}
displayAd2();
#bg2 {
width: 728px;
height: 90px;
margin-top: 40px;
background-color: #0c74b9;
margin-left: auto;
margin-right: auto;
position: relative;
}
#ad_container2 {
position: absolute;
width: 100%;
height: 100%;
margin-left: auto;
margin-right: auto;
opacity: 0;
}
<div id="bg2">
<div id="ad_container2"></div>
</div>
I have total 8 svg files no issue if you provide a better code than this.