louisremi / background-size-polyfill

Adds support for background-size "cover" and "contain" to IE8
http://louisremi.github.com/background-size-polyfill/
MIT License
1.26k stars 359 forks source link

Changing dynamically the background image with IE8 ? #7

Closed sebcante closed 11 years ago

sebcante commented 11 years ago

Hi louisremi,

Thanks for your work it pretty much worked out of the box! Something i am wondering if there is a way to change dynamically the background image via CSS with IE8 and using the htc hook. Let s say you have 2 skins where each of them have a different background images

<div class="skin1">
   <div class="elem> </div>
</div>

.skin1  .elem {
background-image: url(images/img1.jpg);
}
.skin2  .elem {
background-image: url(images/img2.jpg);
} 

.elem{
    background-position: center;
    background-repeat: no-repeat;
    background-size: contain;
    -ms-behavior: url(backgroundsize.min.htc);
}

i managed to display the img1 ok in IE8 , but when i switch the skin css class from skin1 to skin2 the img2 does not showup as if the backgroundsize.min.htc executes once . Do you know if there is a way to reset it ?

thanks

-seb

techhead commented 11 years ago

Seb,

I had this same issue. After swapping out the class name on the element, just change another watched property.

elem.style.backgroundImage=''; worked for me.

On Sun, Feb 3, 2013 at 2:02 AM, sebcante notifications@github.com wrote:

Hi louisremi,

Thanks for your work it pretty much worked out of the box! Something i am wondering if there is a way to change dynamically the background image via CSS with IE8 and using the htc hook. Let s say you have 2 skins where each of them have a different background images