简单整一下元素拖拽
<script type="text/javascript"> var oDiv = document.getElementById('info1'); oDiv.onmousedown = function (env) { var env = env||window.event; var disX = env.offsetX; var disY = env.offsetY; document.onmousemove = function(env){ var env = env||window.event; oDiv.style.left = env.clientX - disX+'px'; oDiv.style.top = env.clientY -disY+'px'; } document.onmouseup =function(){ document.onmousemove = null; } } </script>
<style> #info1{ width: 200px; height: 200px; background: #c599af; position: absolute; cursor: move; } </style> <body> <div id="info1"></div> </body>