riptide
10-06-2012, 08:02 AM
I'm trying to make something similar to a rotating banner with DIVs
I have a code I tried made but it gives weird looping. It won't display one image at time. I cycles between 1 image 3, none 2 and 4 being displayed at once.
I think the if and else are not in sink.
window.onload=function() {
timer = setInterval('flip()', 2500);
}
function flip(){
var div = document.getElementById('displaybox');
var divs = div.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
if(divs[i].style.display != 'block') {
divs[i].style.display = 'block';
}
else {divs[i].style.display = 'none';i++
}
}
}
here is the CSS and html. I know the function is setting everything to display block. I would expect the else clause to remove images 1 by 1.
If it was doing the opposite of what I wanted I could fix it. Strangely I can't find similar scripts on the web.
.window{
display:none;
}
<div id="displaybox">
<div class="window"><span class="dis"></span><img id="image1" src="test2.gif"/></div>
<div class="window"><span class="dis"></span><img id="image2" src="test1.gif"/></div>
<div class="window"><span class="dis"></span><img id="image3" src="test3.png"/></div>
<div calss="window"><span class="dis">4</span><img id="image4" src=""/></div>
<div class="window"><span class="dis">5</span><img id="image5" src=""/></div>
</div>
I have a code I tried made but it gives weird looping. It won't display one image at time. I cycles between 1 image 3, none 2 and 4 being displayed at once.
I think the if and else are not in sink.
window.onload=function() {
timer = setInterval('flip()', 2500);
}
function flip(){
var div = document.getElementById('displaybox');
var divs = div.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
if(divs[i].style.display != 'block') {
divs[i].style.display = 'block';
}
else {divs[i].style.display = 'none';i++
}
}
}
here is the CSS and html. I know the function is setting everything to display block. I would expect the else clause to remove images 1 by 1.
If it was doing the opposite of what I wanted I could fix it. Strangely I can't find similar scripts on the web.
.window{
display:none;
}
<div id="displaybox">
<div class="window"><span class="dis"></span><img id="image1" src="test2.gif"/></div>
<div class="window"><span class="dis"></span><img id="image2" src="test1.gif"/></div>
<div class="window"><span class="dis"></span><img id="image3" src="test3.png"/></div>
<div calss="window"><span class="dis">4</span><img id="image4" src=""/></div>
<div class="window"><span class="dis">5</span><img id="image5" src=""/></div>
</div>