Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You already got your answer. Just wanted to add that jQuery is a bit overkill if this is all you want to do, but it's probably not.</p> <p>Here is a pure javascript solution:</p> <p><a href="http://jsfiddle.net/2BQV5/2/" rel="nofollow">http://jsfiddle.net/2BQV5/2/</a></p> <pre><code>var arr = ['http://placekitten.com/200/300','http://placekitten.com/200/301','http://placekitten.com/200/302']; window.onload = function () { index = 0; var c = document.getElementById('cat'); setInterval(function() { if(index &gt; arr.length-1) {index = 0} c.style.backgroundImage='url(' + arr[index++] + ')'; }, 3000); } </code></pre> <p>Have fun!</p> <p><strong>Edit</strong></p> <p>However for the second request in the comments, to have to pictures fade, jQuery is probably more suited.</p> <p>Here is one way to achieve the fading effect:</p> <p><a href="http://jsfiddle.net/8jWT5/" rel="nofollow">http://jsfiddle.net/8jWT5/</a></p> <pre><code>var arr = ['http://placekitten.com/200/300','http://placekitten.com/200/301','http://placekitten.com/200/302']; $(document).ready(function() { var c = $('#cat'); fade = document.createElement('div'); $(fade).attr('style','position: absolute; width:' + c.width() + 'px; height:' + c.height() + 'px;').attr('id','fade').hide(); c.append(fade); var index = 0; setInterval(function () { $('#fade').css('background-image', 'url(' + arr[index] + ')').fadeIn(500,function() { c.css('background-image', 'url(' + arr[index++] + ')'); if(index &gt; arr.length-1) {index = 0} $(this).hide(); }); }, 3000); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload