I’m trying to make a slideshow that fades between several absolute-positioned div’s. On Chrome, IE9, Opera the code below works fine. But on Firefox, the timeout goes once or twice, then stops. If you remove the JS section marked below, it loops properly.
<style>
.slide {position:absolute; top:0; left:0; width:300px; height:200px}
</style>
<div id="slides" class="slides">
<div class="slide slide1" style="background:#c66">
<div class="swap_links">
<a href="javascript:" class="active">1</a>
<a href="javascript:">2</a>
<a href="javascript:">3</a>
</div>
</div>
<div class="slide slide2" style="background:#6c6">
<div class="swap_links">
<a href="javascript:">1</a>
<a href="javascript:" class="active">2</a>
<a href="javascript:">3</a>
</div>
</div>
<div class="slide slide3" style="background:#36c">
<div class="swap_links">
<a href="javascript:">1</a>
<a href="javascript:">2</a>
<a href="javascript:" class="active">3</a>
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
var fp = '#slides .slide';
var fs = 300;
var t = window.setTimeout(swap, 1000);
$(fp).slice(1).hide();
function swap(to) {
//removing this section, loop plays in FF
if (to) {
$(fp + to).fadeIn(fs);
$(fp).not('.slide' + to).fadeOut(fs);
window.clearTimeout(t);
return;
}
$(fp).eq(1).fadeIn(fs);
$(fp).eq(0).fadeOut(fs, function() {
$(this).appendTo('#slides');
t = window.setTimeout(swap, 1000);
});
}
$('#slides .swap_links a').click(function() {
swap($(this).html());
});
});
</script>
FireFox appears to have been passing arbitrary numeric values to the
tovariable within your function causing theif(to){...}statement to execute if the passed value was anything but 0.To fix this execute the
swap()function without arguments in the setTimeout() like this:Here is the updated demo: http://jsfiddle.net/x6PCD/14/
I hope this helps!