javascript设置DIV位置

来源:互联网 发布:cl邀请码淘宝怎么搜 编辑:程序博客网 时间:2024/05/01 15:54

<div id="myDIV" style="z-index: 9999999; position: absolute; display: none; height: 210px;width350px">

<table>

            <tr style="height: 25px">

                <td class="ModiHead" align="center">

                    各阶段版本信息</td>

            </tr>

            <tr style="height: 100%">

                <td>

                    <div style="visibility: inherit; overflow: auto; width: 100%; height: 100%">

                        <iframe frameborder="0" id="VersionFrame" src="" style="border: 0px; height: 100%;

                            width: 100%;"></iframe>

                    </div>

                </td>

            </tr>

            <tr style="height: 25px">

                <td class="ModiHead" align="center">

                    <a style="cursor: hand" onclick="javascript :document.all['myDIV'].style.display='none';">

                        关 闭</a></td>

            </tr>

        </table>

 

 

/*显示DIV*/

function showDIV()

{

    /*获取当前鼠标左键按下后的位置,据此定义DIV显示的位置*/

    var leftedge    = document.body.clientWidth-event.clientX;

    var bottomedge  = document.body.clientHeight-event.clientY;

   

    /*如果从鼠标位置到窗口右边的空间小于DIV的宽度,就定位DIV的左坐标(Left)为当前鼠标位置向左一个DIV宽度*/

    if (leftedge < myDIV.offsetWidth)

    {

        myDIV.style.left = document.body.scrollLeft + event.clientX - myDIV.offsetWidth;

    }

    else

    {

        /*否则,就定位DIV的左坐标为当前鼠标位置*/

        myDIV.style.left = document.body.scrollLeft + event.clientX;

    }

   

   

    /*如果从鼠标位置到窗口下边的空间小于DIV的高度,就定位DIV的上坐标(Top)为当前鼠标位置向上一个DIV高度*/

    if (bottomedge < myDIV.offsetHeight)

    {

        myDIV.style.top = document.body.scrollTop + event.clientY - myDIV.offsetHeight;

    }

    else

    {

        /*否则,就定位DIV的上坐标为当前鼠标位置*/

        myDIV.style.top = document.body.scrollTop + event.clientY;

    }

   

    /*设置DIV可见*/       

    myDIV.style.display = "block";

   

    return false;

}

原创粉丝点击