Although Pierreβs answer worked for me earlier, I recently came across a situation where this did not happen. Introducing a simple, circular image slider, I use the following.
HTML:
<ul id="slides"> <li class="active"> <img src="/.../0.jpg"> <p>Caption</p> </li> <li class="active"> <img src="/.../1.jpg"> <p>Caption</p> </li> </ul>
CSS
#slides { position: relative; } #slides li { position: absolute; top: 0; display: none; opacity: 0; -moz-transition: opacity 1s; } #slides li.active { display: block; opacity: 1; }
and jQuery:
$(function(){ animateSlide(); }); function animateSlide(){ setTimeout(function(){ var current = $('#slides li.active'); var next = current.next();
This works fine in Safari / Chrome (although I admit it is somewhat fancy with all setTimeout
s), but while the slider was technically working in Firefox, there was no visible transition.
Following Jim Jeffers answer to a similar problem , I was able to get it to work in both Safari / Chrome and Firefox, and also significantly cleared my JavaScript.
Updated CSS:
#slides li { position: absolute; top: 0; height: 0; opacity: 0; -moz-transition: opacity 1s; } #slides li.active { height: auto; opacity: 1; }
Updated jQuery:
function animateSlide(){ setTimeout(function(){ var current = $('#slides li.active'); var next = current.next(); // If there is no next, use the first li if(!next.length){ next = $('#slides li:first'); } current.removeClass('active'); next.addClass('active'); animateSlide(); // Loop }, 6000); // Change image every 6 seconds }
source share