div漂浮

function scrollx(p) {
        var d = document,
        dd = d.documentElement,
        db = d.body,
        w = window,
        o = d.getElementById(p.id),
        ie6 = /msie 6/i.test(navigator.userAgent),
        style,
        timer;
        if (o) {
            o.style.cssText += ";position:" + (p.f && !ie6 ? 'fixed': 'absolute') + ";" + (p.l == undefined ? 'right:0px;': 'left:' + p.l + 'px;') + (p.t != undefined ? 'top:' + p.t + 'px': 'bottom:0');
            if (p.f && ie6) {
                o.style.cssText += ';left:expression(documentElement.scrollLeft + ' + (p.l == undefined ? dd.clientWidth - o.offsetWidth: p.l) + ' + "px");top:expression(documentElement.scrollTop +' + (p.t == undefined ? dd.clientHeight - o.offsetHeight: p.t) + '+ "px" );';
                dd.style.cssText += ';background-image: url(about:blank);background-attachment:fixed;';
            } else {
                if (!p.f) {
                    w.onresize = w.onscroll = function() {
                        clearInterval(timer);
                        timer = setInterval(function() {
                            var st = (dd.scrollTop || db.scrollTop),
                            c;
                            c = st - o.offsetTop + 300;
                            if (c != 0) {
                                o.style.top = o.offsetTop + Math.ceil(Math.abs(c) / 10) * (c < 0 ? -1 : 1) + 'px';
                            } else {
                                clearInterval(timer);
                            }
                        },
                        10)
                    }
                }
            }
        }
    }
    scrollx({
        id: 'Scollbox'
    })
posted @ 2015-11-17 09:49  小猪~~  阅读(175)  评论(0编辑  收藏  举报