慕田峪6924496
2016-08-05 21:31
!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #box{ width: 400px; height: 250px; background-color: #F0FFFF; border: solid cornflowerblue; top: 200px; left: 300px; position: absolute; } #login{ width: 400px; height: 30px; border-bottom: solid cornflowerblue; background-color: cornflowerblue; margin-top:-18px; } #login p{ text-align: center; color:#F0FFFF; font-weight:900; font-size: large; } </style> <script type="text/javascript"> window.onload=drag; function drag(){ var login=document.getElementById("login"); login.onmousedown=fndown(); } function fndown(event){ event=event||window.event; var box=document.getElementById("box"), divx=event.clientX-box.offsetLeft, divy=event.clientY-box.offsetTop; document.onmousemove=function(event){ event=event || window.event; var box=document.getElementById("box"); box.style.left=event.clientX-divx+'px'; box.style.top=event.clientY-divy+'px'; } } </script> </head> <body> <div id="box"> <div id="login"><p>登录</p></div> </div> </body> </html>
问题解决啦 不用了
DOM事件探秘
99545 学习 · 1197 问题
相似问题