I am working for some code with bxslider because I have many large images, the page is loading slowly , I tried any lazy loading plugin, but not work well with bxslider. So finally, I tried to write some code by myself.
I tried to do something, if the div is visible, removeAttr data-style, then add addAttr style. my code in jsfiddle (Omitted code for bxslider):
<div class="bgAnchor" data-style="background:url('http://it.bing.com/az/hprichbg?p=rb%2fNewRiverGorgeBridge_ROW468427072.jpg') no-repeat;background-position:0px 0px;"></div>
<div class="bgAnchor" data-style="background:url('http://it.bing.com/az/hprichbg?p=rb%2fPalmFrond_ROW2095872384.jpg') no-repeat;background-position:0px 0px;"></div>
<div class="bgAnchor" data-style="background:url('http://it.bing.com/az/hprichbg?p=rb%2fJacksonSquare_ROW1364682631.jpg') no-repeat;background-position:0px 0px;"></div>
<div class="bgAnchor" data-style="background:url('http://it.bing.com/az/hprichbg?p=rb%2fAustraliaClouds_ROW1600390948.jpg') no-repeat;background-position:0px 0px;"></div>
$('.bgAnchor').each(function(){
if($(this).is(":visible")){
var data_style = $(this).attr('data-style');
if(data_style!== 'undefined' && data_style!== false){
var attr_image = $(this).attr("data-style");
$(this).css('background',attr_image).removeAttr("data-style");
}
}
});
but I am not sure why it is not work. I am pleasure if any one can help me. many thanks.
from jQuery css() page
this means that you can’t use background in css()
so you have to do it with style attribute.
here is jsFiddle page