<html>
<script language="JavaScript">
<!--
var divTop,divLeft,divWidth,divHeight,docHeight,docWidth,objTimer;
function getMsg()
{
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10);
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10);
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight + parseInt(document.body.scrollTop,10) + 5;
document.getElementById("eMeng").style.left = docWidth + parseInt(document.body.scrollLeft,10) - divWidth ;
document.getElementById("eMeng").style.visibility="visible";
objTimer = window.setInterval("moveDiv()",10);
}function resizeDiv()
{
divHeight = parseInt(document.getElementById("eMeng").offsetHeight,10);
divWidth = parseInt(document.getElementById("eMeng").offsetWidth,10);
docWidth = document.body.clientWidth;
docHeight = document.body.clientHeight;
document.getElementById("eMeng").style.top = docHeight + parseInt(document.body.scrollTop,10) - divHeight ;
document.getElementById("eMeng").style.left = docWidth + parseInt(document.body.scrollLeft,10) - divWidth;
}function moveDiv()
{
if(parseInt(document.getElementById("eMeng").style.top,10) < (docHeight - divHeight + parseInt(document.body.scrollTop,10)))
{
window.clearInterval(objTimer);
return;
}
divTop = parseInt(document.getElementById("eMeng").style.top,10);
document.getElementById("eMeng").style.top = divTop - 2;
}
function closeDiv()
{
document.getElementById('eMeng').style.visibility="hidden";
if(objTimer) window.clearInterval(objTimer);
}
window.onload = getMsg;
window.onresize = resizeDiv;
window.onscroll = resizeDiv;
-->
</script>
<body>
<div id="eMeng" style="border:1px solid #7788CC;visibility:hidden;position:absolute;top:0px;left:0px;height:150px;width:260px;">
  <div style="background-color:#7788FF;width:260px;height:20px;">
    <div style="cursor:hand;font-size:12px;font-weight:bold;text-align:right;" onclick="closeDiv()">×</div>
  </div>
  <div style="border:3px solid #BBCCFF;background-color:#D5E7FD;width:260px;height:130px;">
  <center>
    <span>HelloWorld</span>
  </center>
  </div>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>

解决方案 »

  1.   

    给个带动的。
    var css = {divCss:'butarea',buthide:'buthide normolText',butCss:{save:'input_save',del:'input_delete',sub:'input_submit',back:'input_back',add:'input_insert',print:'input_print',preview:'input_printview',printset:'input_printview'}};
    var imgPath = '/images/declare/pop05.gif';
    var cof;
    var compat = document.compatMode == 'BackCompat' ? false : true;
    var scrollExtra = false; //额外调整水平方向一个滚动条位置.
    /****
     cfg.pos:down 下(默认) top 上
     cfg.width 高度 cfg.height 宽度
     cfg.buts:定制button按钮 {save:{title:saveT,fn:saveF},del:{title:delT,fn:delF}}   前为按钮类型,后为按钮响应函数。
     */
    function initButArea(cfg) {
        var butArea = document.getElementById('butArea');
        if (!butArea) {
            butArea = document.createElement('div');
            butArea.id = 'butArea';
            butArea.style.position = 'absolute';
            butArea.className = css.divCss;
            //隐藏按钮
            var img = document.createElement('div');
            img.id = 'hideImg';
            img.style.position = 'absolute';
            img.style.cursor = 'pointer';
            img.innerHTML = hidetitel;
            img.className = css.buthide;
    //        img.src = imgPath;
            //        img.style.border = '5px red solid';
            //        butArea.appendChild(img);
            img.onclick = function() {
                if (butArea.style.display == 'none') {
                    butArea.style.display = 'block';
                    img.innerHTML = hidetitel;
                } else {
                    butArea.style.display = 'none';
                    img.innerHTML = showtitel;
                }
            }
            //加入按钮
            addButs(butArea, cfg.buts);
            document.body.appendChild(butArea);
            document.body.appendChild(img);
            if (cfg) {
                cof = cfg;
                butArea.style.width = cfg.width || '100%';
                butArea.style.height = cfg.height || 35;
                cfg.bheight = butArea.offsetHeight;
                img.style.height = butArea.style.height;
                img.style.lineHeight = butArea.clientHeight + 'px';
                img.overflow = 'hidden';
                improve(0, 0);
                ;
            }
        }}function addButs(div, buts) {
        if (buts.save) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.save;
            but.onclick = buts.save.fn;
            but.value = buts.save.title;
            div.appendChild(but);
        }
        if (buts.del) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.del;
            but.onclick = buts.del.fn;
            but.value = buts.del.title;
            div.appendChild(but);
        }
        if (buts.sub) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.sub;
            but.onclick = buts.sub.fn;
            but.value = buts.sub.title;
            div.appendChild(but);
        }
        if (buts.back) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.back;
            but.onclick = buts.back.fn;
            but.value = buts.back.title;
            div.appendChild(but);
        }
        if (buts.add) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.add;
            but.onclick = buts.add.fn;
            but.value = buts.add.title;
            div.appendChild(but);
        }
        if (buts.print) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.print;
            but.onclick = buts.print.fn;
            but.value = buts.print.title;
            div.appendChild(but);
        }
        if (buts.preview) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.preview;
            but.onclick = buts.preview.fn;
            but.value = buts.preview.title;
            div.appendChild(but);
        }
        if (buts.printset) {
            var but = document.createElement('input');
            but.type = 'button';
            but.className = css.butCss.printset;
            but.onclick = buts.printset.fn;
            but.value = buts.printset.title;
            div.appendChild(but);
        }
    }
    function improve(st, sl) {
        var butArea = document.getElementById('butArea');
        var img = document.getElementById('hideImg');
        if (butArea) {
            //处理百分比宽度
            if (cof.width.indexOf('%')) {
                var ew = 0;
                if (compat) {
                    ew = parseInt(butArea.currentStyle.paddingLeft) + parseInt(butArea.currentStyle.paddingRight) + 2;
                }
                butArea.style.width = (document.documentElement.clientWidth || document.body.clientWidth) * parseInt(cof.width) * 0.01 - ew + 'px';
            }
            if (cof.pos == 'top') {
                butArea.style.top = st;
                butArea.style.left = sl;
                img.style.top = butArea.style.top;
                img.style.left = butArea.style.left;
            } else {
                butArea.style.top = st + (document.documentElement.clientHeight || document.body.clientHeight) - cof.bheight - (scrollExtra ? 17 : 0) + 'px'; //butArea.offsetHeight;
                butArea.style.left = sl + 'px';
                img.style.top = butArea.style.top //butArea.offsetHeight;
                img.style.left = butArea.style.left;
            }
        }}//document.documentElement.onresize = function() {
    //    improve(document.documentElement.scrollTop, document.documentElement.scrollLeft);
    //}
    //document.documentElement.onscroll = function() {
    //    improve(document.documentElement.scrollTop, document.documentElement.scrollLeft);
    //}window.onresize = function() {
        improve(document.documentElement.scrollTop || document.body.scrollTop, document.documentElement.scrollLeft || document.body.scrollLeft);
    }
    window.onscroll = function() {
        improve(document.documentElement.scrollTop || document.body.scrollTop, document.documentElement.scrollLeft || document.body.scrollLeft);
    }
    function scrollStaut(flag) {
        scrollExtra = flag;
    }