• fixed定位


    function fixedBar(o){
        var bar = document.getElementById(o.id),
            width = bar.offsetWidth,
            height = bar.offsetHeight,
            dir = o.dir,
            at = o.at,
            left = o.left,
            right = o.right,
            top = o.top,
            bottom = o.bottom,
            body = document.body,
            html = document.documentElement;
        //css:left right top bottom
        var    posCss = 'position:fixed;_position:absolute;';
        if(at != 1){
            left = right =     ((Math.max(html.clientWidth, html.scrollWidth) - at)/2 - width);
        }
        if(dir=='lt'){
            posCss = posCss + 'left:'+left+'px;top:'+top+'px;';
        }else if(dir=='lb'){
            posCss = posCss + 'left:'+left+'px;bottom:'+bottom+'px;';
        }else if(dir=='rt'){
            posCss = posCss + 'right:'+right+'px;top:'+top+'px;';
        }else if(dir=='rb'){
            posCss = posCss + 'right:'+right+'px;bottom:'+bottom+'px;';
        }
        bar.style.cssText = posCss;
        //ie6
    var isIE = !!window.ActiveXObject;
    var isIE6 = isIE && !window.XMLHttpRequest;
        if(isIE6){
            //scrollTop    
            function getPageScroll(){
                var yScroll; 
                if (html && html.scrollTop){ 
                    yScroll = html.scrollTop; 
                } else if (body) { 
                    yScroll = body.scrollTop; 
                } 
                return yScroll; 
            }
            if(dir=='lt' || dir=='rt'){
                onscroll = function(){
                    bar.style.top = (getPageScroll() + top) + 'px';
                }
            }else if(dir=='lb' || dir=='rb'){
                onscroll = function(){
                    bar.style.top = (getPageScroll() + html.clientHeight - (height+bottom)) + 'px';
                }
            }
            
        }
    }
    fixedBar({'id':'fixed','dir':'lt','at':1,'top':20,'left':0});
    *html{background-image:url(about:blank);background-attachment:fixed;}
    

      只有定位一个功能,可以定在左上,左下,右上,右下。可以以全屏为基准(at设置为1,取100%的意思),以内容宽度为准(假如定位在1002宽度的边上,at设置为1002)。

  • 相关阅读:
    实验10:Problem D: STL——管道二
    实验10:Problem C: STL——呵呵型自动机
    实验10:Problem B: STL——哈哈型自动机
    实验10:Problem A: STL——整理唱片
    实验9:Problem I: 学生干部虚基类
    hihocoder1994 树与落叶 DFS+前缀和+二分
    [Offer收割]编程练习赛108
    【模板】左偏树(可并堆)
    P2993 [FJOI2014]最短路径树问题 点分治+最短路
    E
  • 原文地址:https://www.cnblogs.com/bianyuan/p/2646709.html
Copyright © 2020-2023  润新知