Animate opacity doesn't work properly on IE

前端 未结 14 859
广开言路
广开言路 2020-12-23 14:13

I\'m trying to use animate() to change the height and opacity of a div. The div has an image background in CSS. It works fine on Firefox and Safari

14条回答
  •  盖世英雄少女心
    2020-12-23 15:09

    I've been having the same problem. I stumbled into the answer, when I set the opacity to 40%:

    $('#list_box').stop().animate({opacity: '.4'},"slow");
    

    I noticed that made the opacity jump to 100%, then animate down to 40%. Eureka.

    So, now I explicitly set the opacity to zero before the animation:

    $('#list_box').css({opacity:0}).stop().animate({opacity: '1'},"slow");
    

    That animates smoothly, except the text still looks horrible in IE.

    To clean up the text, I removed the opacity from the css in IE after the animation. This seems to clear up the text quite a bit in IE6 and IE8.

    $('#list_box').css({opacity:0}).stop().animate({opacity: '1'},"slow",function(){
        //remove the opacity in IE
        jQuery.each(jQuery.browser, function(i) {
            if($.browser.msie){
                $('#list_box').css({opacity:''});
            }
        });
    });
    

    I'm testing it on a Mac in Parallels, in IE6 and IE8. Everything seems to work fine on the Mac side.

提交回复
热议问题