mousedown 的时候创建拖动对象,mouseup的时候释放对象,原理弄清楚了其实很简单。
简单拖拽实现代码:
简单拖拽实现 *{margin:0;padding:0;} #box{ margin:20px auto; position:relative; width:400px; height:400px; background:#ccc; border:1px solid #333; postion:relative; } #dragBox{ width:50px; height:50px; text-align:center; line-height: 50px;position: absolute; background:blue; cursor:move; font-size:12px; color:#fff;} 拖我 [Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
