ie6 css 實現fixed漂浮

首先:調試工具 javascript

因爲ie6 沒有調試工具也沒有console,在網上查了也不上,最終採用alert()定位,和firebug lite 調試頁面
css

Firebug Lite簡單 安裝過程能夠參考:http://www.woiweb.net/firebug-lite-debug.htmlhtml

對於ie6中postion 位置的理解,ie6 沒有fixed而對於不少小的tags  通常的漂浮都須要相對定位,java


首先:  查到了  expression 這個ie6 和ie5 動態賦值css的屬性,是早期微軟DHTML的產物。web

有了這個東西,就能夠結合eval(),經過javascript進行獲取高度。
express


而後 :就是獲取高度了dom

    因爲absolute = scroll(捲起高度)+client(屏幕高度)工具

    因此獲得  top=document.documentElement.scrollTop+document.documentElement.clientHeight-myheight)post

最終:_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-340))this


這樣子就能夠在ie6 下達到底部漂浮的效果,一段css代碼,實現漂浮

.float_tab{(

position:fixed;

_position:absolute;

zindex:5010;

right:5px;

bottom:5px;

_bottom:auto;

_top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-340))}


另外還有一種是查到的封裝好的代碼,分享一下

直接調用 。position.fixed  就行,自動識別

position:function(){

        var isIE6 = !-[1,] && !window.XMLHttpRequest,

            html = document.getElementsByTagName('html')[0],

            dd = document.documentElement,

            db = document.body,

            dom = dd || db,

        // 獲取滾動條位置

            getScroll = function(win){

                return {

                    left: Math.max(dd.scrollLeft, db.scrollLeft),

                    top: Math.max(dd.scrollTop, db.scrollTop)

                };

            };

        if (isIE6 && document.body.currentStyle.backgroundAttachment !== 'fixed') {

            html.style.backgroundImage = 'url(about:blank)';

            html.style.backgroundAttachment = 'fixed';

        };

        return {

            fixed: isIE6 ? function(elem){

                var style = elem.style,

                    doc = getScroll(),

                    dom = '(document.documentElement || document.body)',

                    left = parseInt(style.left) - doc.left,

                    top = parseInt(style.top) - doc.top;

                this.absolute(elem);

                style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');

                style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');

            } : function(elem){

                elem.style.position = 'fixed';

            },

            absolute: isIE6 ? function(elem){

                var style = elem.style;

                style.position = 'absolute';

                style.removeExpression('left');

                style.removeExpression('top');

            } : function(elem){

                elem.style.position = 'absolute';

            }

        };

    }(),

相關文章
相關標籤/搜索