今天在写一个展开且滚动的效果的时候,发现了display:list-item不兼容IE7和IE6。


初始代码:

$(document).ready(function(){
    $(".question_list li:not(.box_hide)").each(function(){
        $(this).click(function(){
            $(this).next(".box_hide").toggle();
            $(this).siblings("li").next(".box_hide").hide();
            $(this).children("a").css("color","#EC7302");
            var ptop=$(this).parent().offset().top;
            var ph=$(this).parent().height();
            var ttop=$(this).offset().top;
            var pstop=$(this).parent().scrollTop();
            var nh=$(this).next(".box_hide").height();
            if(($(this).next(".box_hide").css('display')=="list-item")&&((ptop+ph-ttop-nh-39)<0)){
                if(ph>nh+39){
                    var len=pstop-(ptop+ph-ttop-nh)+39;
                    $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
                }else{
                    var len=pstop+(ttop-395);
                    $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
                };
            }else if(($(this).next(".box_hide").css('display')=="list-item")&&((ttop-395)<0)){
                var len=pstop+(ttop-395);
                $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
            };
        });
    });
});



修改后的代码:

$(document).ready(function(){
    $(".question_list li:not(.box_hide)").each(function(){
        $(this).click(function(){
            $(this).next(".box_hide").toggle();
            $(this).siblings("li").next(".box_hide").hide();
            $(this).children("a").css("color","#EC7302");
            var ptop=$(this).parent().offset().top;
            var ph=$(this).parent().height();
            var ttop=$(this).offset().top;
            var pstop=$(this).parent().scrollTop();
            var nh=$(this).next(".box_hide").height();
            if(($(this).next(".box_hide").css('display')!="none")&&((ptop+ph-ttop-nh-39)<0)){
                if(ph>nh+39){
                    var len=pstop-(ptop+ph-ttop-nh)+39;
                    $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
                }else{
                    var len=pstop+(ttop-395);
                    $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
                };
            }else if(($(this).next(".box_hide").css('display')!="none")&&((ttop-395)<0)){
                var len=pstop+(ttop-395);
                $(this).parent().animate({scrollTop:len},"normal","linear",function(){});
            };
        });
    });
});

以上两段代码就是$(this).next(".box_hide").css('display')=="list-itme"和$(this).next(".box_hide").css('display')!="none"这两句的差异。前者不兼容IE7和IE6,后者兼容。


我是这样做打印才知道问题出在list-item的。

我var d=$(this).next(".box_hide").css('display'),然后alert(d),在谷歌和火狐里都能打印出list-item,但是在IE7里只能打印出block,由此可见,display:list-item是不兼容IE7和IE6的,所以我稍微更改了代码后,我的效果就都能兼容了。