views:

2101

answers:

2

I have the following HTML:

<div id="similar-products" class="box small">
 <div class="product">
  <h3><a href="#">Lorem ipsum 1</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 2</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 3</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 4</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 5</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 6</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 7</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
 <div class="product">
  <h3><a href="#">Lorem ipsum 8</a></h3>
  <p class="figure"><img src="_img/thumb/blah.png" alt=""></p>
  <p class="price">€ 19,99</p>
  <p class="more-info"><a href="#more-info">More info</a></p>
  <p class="add-to-cart"><a href="#add">Add to shopping bag</a></p>
 </div>
</div>

I want to cycle through these products in groups of four. So I'm using the following JavaScript (jQuery):

// Wrap every four elements in a DIV
var elems = $('#similar-products div');
for (var i = 0; i < elems.length; i += 4) {
 elems.slice(i, i + 4).wrapAll('<div class="wrap">'); // split of four and wrap them in another DIV
}

$('#similar-products').after('<p class="next"><a href="#next">Next 4 suggestions</a></p>');

alert('Before this alert(), things look fine, even in IE!');

// Invoke the jQuery Cycle plugin; this causes the CSS background image of #similar-products to disappear in IE
$('#similar-products').cycle({ fx: 'scrollHorz', speed: 1000, timeout: 0, next: $('.next') });

As you can see, after invoking the Cycle plugin, the CSS background image of #similar-products disappears in IE.

Things I already tried:

  • #similar-products, #similar-products .wrap, #similar-products .wrap div { position: relative; }
  • Setting hasLayout for IE: #similar-products, #similar-products .wrap, #similar-products .wrap div { zoom: 1; hasLayout: true; }

How can I stop the background image from disappearing in IE?

A: 

I've had similiar issues when using JQuery after calling a function on a div. I found that re-applying the background-image after calling the function usually works.

Ian Devlin
Thanks for the tip. Unfortunately $('#similar-products').css('backgroundImage', 'url(_css/img/box-small.png)'); didn't seem to work in IE -- though in other browsers, it worked fine.
Mathias Bynens
Try just setting it using document.getElementById('similar-products').style.backgroundImage = "url('_css/img/box-small.png')";
Ian Devlin
+3  A: 

You have to set the property cleartypeNoBg to true, as they say on the options reference

$('#similar-products').cycle({ cleartypeNoBg: true, fx: 'scrollHorz', speed: 1000, timeout: 0, next: $('.next') });
tanathos
Thank you so much!
Mathias Bynens