zoukankan      html  css  js  c++  java
  • js 鼠标移动div

    <HTML>
    
    <head>
    <style type="text/css">
            .divBody{
     //margin-top:20px;
     border: solid #CCC 1px;
     width:500px;
     height:400px;
     position:relative;
     z-index:0;
     margin-left:auto; 
     margin-right:auto;
     }
     .divHead{
     width:500px;
     height:50px;
     background-color:#CCC;
     }
     .content
     {
     width:500px;
     height:300px;
     }
     .tail{
     background:#CCC;
     height:50px;
     width:500px;
     display:table-cell;
     vertical-align:middle;
     }
        </style>
    
    </head>
    <BODY>
    <div class="divBody" id="divBody" style="left: 29px; top: 14px;"> <!--这里要加style="left: 29px; top: 14px;" 否则有问题-->
     <div class="divHead" id="divHead" style="cursor: move;">
     </div>
     <div class="content">
     </div>
     <div class="tail">
     </div>
     </div>
    <SCRIPT>
    var posX;
     var posY;
     fdiv = document.getElementById("divBody");
     document.getElementById("divHead").onmousedown=function(e)
     {
     if(!e) e = window.event; //IE
     posX = e.clientX - parseInt(fdiv.style.left);
     posY = e.clientY - parseInt(fdiv.style.top);
     document.onmousemove = mousemove;
     }
    
     document.onmouseup = function()
     {
     document.onmousemove = null;
     }
    
    
     function mousemove(ev)
     {
     if(ev==null) ev = window.event;//IE
     fdiv.style.left = (ev.clientX - posX) + "px";
     fdiv.style.top = (ev.clientY - posY) + "px";
     }
    </SCRIPT>
    </BODY>
    </HTML>
  • 相关阅读:
    P3507 [POI2010]GRA-The Minima Game
    P2038 无线网络发射器选址
    2017.9.23清北第二场
    P3183 [HAOI2016]食物链
    2017.9.17校内noip模拟赛解题报告
    Day2代码
    P1328 生活大爆炸版石头剪刀布
    Fibinary Numbers
    Mac os 进行Android开发笔记(1)
    python中文注释及输出出错
  • 原文地址:https://www.cnblogs.com/spider024/p/3018646.html
Copyright © 2011-2022 走看看