首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

尽量短的写一个JS拖动

2012-09-19 
尽可能短的写一个JS拖动title尽可能短的写一个JS拖动/titlebodydiv iddemo stylewidth:100px

尽可能短的写一个JS拖动

<title>尽可能短的写一个JS拖动</title><body><div id="demo" style="width:100px; height:100px; position:absolute; background-color:silver;"></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>

热点排行