Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><a href="http://output.jsbin.com/fakosu/7/" rel="nofollow noreferrer"><em>Use-case</em> jsBin Demo</a></strong></p> <p>In order to Cross-fade a background image, you'll need an extra layer to overlay your gallery.<br> Here's an example of the logic involved:</p> <p><a href="https://i.stack.imgur.com/5JpS8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5JpS8.png" alt="Fade loop background images"></a></p> <p>So create a DIV an place into it normal <code>&lt;img&gt;</code> tags for the browser to pre-load images, we'll use their <code>src</code> afterwards to use as covered <code>background-image</code> for the two elements:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>jQuery(function($) { var $gallery = $("#gallery"); // Your HTML gallery var $overlay = $("&lt;div/&gt;"); // An overlay to X-fade var $images = $gallery.find("img"); var n = $images.length; // How many images we have var c = 0; // Just a counter to loop using Reminder Operator % $gallery.css({backgroundImage: "url("+ $images[c].src +")"}).append( $overlay ); (function loopBg(){ $overlay.hide().css({backgroundImage: "url("+ $images[++c%n].src +")"}).delay(2000).fadeTo(1200, 1, function(){ $gallery.css({backgroundImage: "url("+ $images[c%n].src +")"}); loopBg(); }); }()); });</code></pre> <pre class="snippet-code-css lang-css prettyprint-override"><code>html, body{ height:100%; margin:0; /*If needed*/ } #gallery, /*Your gallery ID */ #gallery &gt; div /*Immediate DIV child, created by jQuery*/ { position:absolute; width: 100%; height:100%; background: #000 none 50% / cover; } #gallery img{ display:none; /*Exactly. We'll use them as BG images*/ }</code></pre> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt; &lt;div id="gallery"&gt; &lt;!-- We'll not show images, those are just used for the browser to preload them Let's just steal the images Sources and use them for the #gallery and #overlay backgrounds --&gt; &lt;img src="http://dummyimage.com/600x365/fc5/fff&amp;text=Image1" /&gt; &lt;img src="http://dummyimage.com/600x365/cf5/fff&amp;text=Image2" /&gt; &lt;img src="http://dummyimage.com/600x365/f5c/fff&amp;text=Image3" /&gt; &lt;/div&gt;</code></pre> </div> </div> </p>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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