Animate opacity doesn't work properly on IE

前端 未结 14 840
广开言路
广开言路 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条回答
  •  -上瘾入骨i
    2020-12-23 14:57

    I solved it with adding an opaque background to the animated element:

    CSS:

    .overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 195px;
        height: 274px;
        cursor: pointer;
        background: #fff url('../images/common/image_hover.png') 0 0 no-repeat; /* the solution */
        opacity: 0;
        -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)"; /* IE8 */
        filter: alpha(opacity=0); /* IE6-7 */     
        zoom: 1;
    }
    

    JS:

    $('.overlay').hover(
        function(){
            $(this).animate({'opacity': 0.7}, 300);
        },
        function(){
            $(this).animate({'opacity': 0}, 250);
        }
    );
    

    Works for IE7-8

    Hope this will help someone ;)

提交回复
热议问题