As many of you will be aware, animating PNG's with alpha transparency in <IE8
does not work very well. Therefore I would simply like to disable animating opacity in <IE8
.
The only way I can see doing something like this is by doing this:
HTML
<!--[if lt IE 8]>
<script type="text/javascript">
var browserUnsupported = true;
</script>
<![endif]-->
JAVASCRIPT
// Test if the browser is supported
if(browserUnsupported){
// Hide the element
$('#test').hide();
}else{
// Fade out the element and then hide it
$('#test').animate({
opacity:0
},200,function(){
$(this).hide();
})
}
// Once the animation has completed, continue
setTimeout(function(){
// This will execute once the animation has completed
// We cannot use the callback in case the browser is unsupported
// and the animate function has not been used
},200);
But this is a pretty long winded fix, especially if you consider that every time I would like to animate something, I have to do this.
Can anybody come up with any better alternatives?
Can you turn of animating opacity in Internet Explorer 8 and below? If there is a hack, please consider that I do not store my jQuery locally, I load it from the Google CDN. I will not be willing to alter the jQuery source, even if this is the only option.
UPDATE
I am not looking for a better method of detecting the browser version. The above code was just for illustrative purposes. What I would like to know is whether there is a way I can control the opacity animating by jQuery? Or, is there a better way to animate if condition, don't animate if not?
UPDATE
Something like this (not tested):
function myAnimate(styles,duration,easing,callback){
// Get the selected element
var element = this.elements;
if($.browser.msie && $.browser.version<8){
delete options.opacity;
}
// Call the animation method
element.animate(options,duration,easing,callback);
}