漂浮DIV“窗口”(或漂浮广告)——fireFox、IE下均适用

//HTML 
<div id="opwindow" class="login" style="display: none">
        <div id="opwindowtitle">
            <div id="optitle" class="logintitlestr">
                会员登录</div>
            <div id="closeopwindow" onclick="closewindow()" onmouseover="overclose(this)" onmouseout="outclose(this)">
                ×</div>
        </div>
        <div id="opcontent">
       
        </div>
    </div>

//CSS


//JS:

var ww="窗口"宽度;//不带px,纯数字
var wh="窗口"高度;//不带px,纯数字


 //移动窗口
 function moveWindow(winname)
 {
    var h1 = document.body.clientHeight;
    var h2 = document.documentElement.clientHeight;
    var isXhtml = (h2<=h1&&h2!=0)?true:false; //判断当前页面的Doctype是否为Xhtml
    var body = isXhtml?document.documentElement:document.body;

    var o=document.getElementById(winname);
    var lf=(body.clientWidth-ww)/2-50;
    o.style.left=lf+"px";
    o.style.top=(document.body.scrollTop?document.body.scrollTop:document.documentElement.scrollTop) +
      ((document.documentElement.clientHeight == 0)?document.body.clientHeight:document.documentElement.clientHeight)
      -wh-200+'px';
    if(o.style.display=="")
    setTimeout("moveWindow('"+winname+"')",20);
 }


function closewindow()
 {
    document.getElementById("login").style.display="none";
    document.getElementById("opwindow").style.display="none";
 }
 function overclose(o)
 {
    o.style.backgroundColor="#F6F2EA";
    o.style.color="#F10000";
 }
 function outclose(o)
 {
    o.style.backgroundColor="#D4D0C8";
    o.style.color="#000000";
 }
posted @ 2007-07-25 18:23  吾非无心  阅读(3709)  评论(0编辑  收藏  举报