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';

            }

        };

    }(),

相关文章
相关标签/搜索