Javascript简短代码实现层拖动效果,函数本身仅用了287个字符,是不是够短呢?据作者称,如果不是为了考虑兼容性,还可以弄的更短一些,为了更好的使用,我看还是不要了吧。 示例: <title>尽可能短的写一个JS拖动</title> <body> <div id="demo" style="width:100px; height:100px; position:absolute; background-color:silver;">veryhuo.com</div> <script> function dragable(id){var d=document,o=d.getElementById(id),s=o.style,x,y,p='onmousemove';o.onmousedown=function(e){e=e||event;x=e.clientX-o.offsetLeft;y=e.clientY-o.offsetTop;d[p]=function(e){e=e||event;s.left=e.clientX-x+'px';s.top=e.clientY-y+'px'};d.onmouseup=function(){d[p]=null}}} dragable("demo"); </script><br /><center>如不能显示效果,请按Ctrl+F5刷新本页,更多网页代码:<a href='http://www.veryhuo.com/' target='_blank'>http://www.veryhuo.com/</a></center>提示:可修改后代码再运行! 文章导航 js点击弹出层代码,js弹出可关闭的遮罩层多年以后,为何企业依然纠结于本地ERP VS 云ERP?