Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First you need to think off when you want to swap. For example you could switch everytime when its a div tag thats loaded. In my example i just used a extra data field "background" and whenever its set the image is applied as a background image.</p> <p>Then you just have to load the Data with the created image tag. And not overwrite the img tag instead apply a css background image.</p> <p>Here is a example of the code change: </p> <pre><code>if (settings.appear) { var elements_left = elements.length; settings.appear.call(self, elements_left, settings); } var loadImgUri; if($self.data("background")) loadImgUri = $self.data("background"); else loadImgUri = $self.data(settings.data_attribute); $("&lt;img /&gt;") .bind("load", function() { $self .hide(); if($self.data("background")){ $self.css('backgroundImage', 'url('+$self.data("background")+')'); }else $self.attr("src", $self.data(settings.data_attribute)) $self[settings.effect](settings.effect_speed); self.loaded = true; /* Remove image from array so it is not looped next time. */ var temp = $.grep(elements, function(element) { return !element.loaded; }); elements = $(temp); if (settings.load) { var elements_left = elements.length; settings.load.call(self, elements_left, settings); } }) .attr("src", loadImgUri ); } </code></pre> <p>the loading stays the same </p> <pre><code>$("#divToLoad").lazyload(); </code></pre> <p>and in this example you need to modify the html code like this:</p> <pre><code>&lt;div data-background="http://apod.nasa.gov/apod/image/9712/orionfull_jcc_big.jpg" id="divToLoad" /&gt;​ </code></pre> <p>but it would also work if you change the switch to div tags and then you you could work with the "data-original" attribute.</p> <p>Here's an fiddle example: <a href="http://jsfiddle.net/dtm3k/1/" rel="noreferrer">http://jsfiddle.net/dtm3k/1/</a></p>
    singulars
    1. This table or related slice is empty.
    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