兼容问题

①浏览器滚动条位置兼容

IE Firefox

document.documentElement.scrollTop;
document.documentElement.scrollLeft;

Chrome

document.body.scrollTop;
document.body.scrollTop;

②JS无法直接获取非行内样式

    window.getComputedStyle(ele,null);
    //IE
    ele.currentStyle.width;
    //封装成兼容函数
    function getStyle(obj, attr) {
        if ( obj.currentStyle ) {
            return obj.currentStyle[attr];
        }
        else {
            return getComputedStyle( obj, null )[attr];
        }
    }

③判断IE6

    //全世界最短判断IE6
    if ( !-[1,]) {
        //IE6
    }
    else {
        //其他浏览器
    }

    //最无争议
    if ( window.VBArray ) {
        //IE
    }
    else {
        //其他浏览器
    }
posted @ 2016-09-07 09:41  Asambojur  阅读(99)  评论(0)    收藏  举报