日期:2014-05-16  浏览次数:20357 次

Javascript提示窗口并实现模式窗口功能
提示窗口的界面:




 
 img{
     border:0px;
 }
 
 #overlay{
     position: absolute;
     top: 0;
     left: 0;
     z-index: 99;
     width: 100%;
     height: 500px;
     background-color: #000;
     filter:alpha(opacity=70);
     -moz-opacity: 0.6;
     opacity: 0.6;
 }
 
 .floatDiv{
     padding:0 0 0 0;    
     position:absolute; 
     width:300px; 
     margin:0 0 0 0; 
     z-index:100;
     border:1px solid #DADADA; 
     background:#FFF; padding:1px;
 }
 
 .floatDiv .divTitle{
     background:#E0E0E0 url('../images/dragForm/title_bg.gif');
     background-position:top left;
     background-repeat:repeat-x;
     height:25px;
     line-height:25px;
     padding:0px 4px;
     cursor:default;
 }
 
 .floatDiv .divContent{
     padding:3px; 
     min-height:100px;
     height:auto; cursor:default;
 }
 
 .floatDiv .divFoot{
     background:#F0F0F0; 
     text-align:right; 
     padding:4px;
     background:#E0E0E0 url('../images/dragForm/bottom_bg.gif');
     background-position:top left;
     background-repeat:repeat-x;
 }
 
 .floatDiv input.divButton{
     background:#E0E0E0 url('../images/dragForm/button_bg.gif');
     background-position:top left;
     background-repeat:repeat-x;
     border:1px solid #D1D3D2;
     height:21px;
     font-size:12px;
     padding:2px 5px;
     color:#626264;
 }
 


function $(_sId)
{return document.getElementById(_sId);}
  
function moveDiv(event, _sId)
{
    var oObj = $(_sId);    
    oObj.onmousemove = mousemove;
    oObj.onmouseup = mouseup;
    oObj.setCapture ? oObj.setCapture() : function(){};
    oEvent = window.event ? window.event : event;
    var dragData = {x : oEvent.clientX, y : oEvent.clientY};
    var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
   
    function mousemove()
    {
        var oEvent = window.event ? window.event : event;
        var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
        var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
        oObj.style.left = iLeft;
        oObj.style.top = iTop;
        dragData = {x: oEvent.clientX, y: oEvent.clientY};  
    }
   
    function mouseup()
    {
        var oEvent = window.event ? window.event : event;
        oObj.onmousemove = null;
        oObj.onmouseup = null;
        if(oEvent.clientX < 1 || oEvent.clientY < 1)
        {
            oObj.style.left = backData.y;
            oObj.style.top = backData.x;
        }
            oObj.releaseCapture ? oObj.releaseCapture() : function(){};
    }
}

function closeDiv(_sID)
{
    var oObj = $(_sID);
    var overlay = $("overlay");    
    if(overlay != null)
    {
        overlay.outerHTML = "";
    }
    oObj.style.display = "none";
    
}

function showDiv(_sID,event)
{
    var arrySize = getPageSize();
    var oObj = $(_sID);
    //创建一个DIV,改名为 overlay 这个是透明的层    
    var oDiv =document.createElement("div");
    oDiv.id = "overlay";
    document.body.appendChild(oDiv);
    var overlay = $("overlay");
    overlay.style.height = arrySize[1];
    overlay.style.width = arrySize[0];
    //alert(arrySize[1]);    
    if(event == null)
    {
        if(oObj.style.left == "")
        {
            oObj.style.left = arrySize[0] / 2 - 150 ;
        }
        
        if(oObj.style.top == "")
        {
            oObj.style.top =  arrySize[0] / 2;
        }        
    }
    else
    {        
        var iEvent= window.event ? window.event : event;        
        oObj.style.left = arrySize[0] / 2 - 150 ; // iEvent.clientX;
        oObj.style.top = arrySize[1] / 2 - 150 ;// iEvent.clientY;
        
    }
    
    oObj.style.display = "block";
    overlay.style.display = "block";
    overlay.style.zindex = oObj.style.zindex - 1;
}

//取得页面大小
function getPageSize(){
    
    var xSc