cutesource 发表于 2013-1-29 13:07:57

JavaScript Google IG Drag Demo(转)

效果演示地址:http://www.phzzy.org/code/drag/google_drag.html
加强版效果演示地址:http://www.phzzy.org/code/drag/google_drag_2.html
拖拽原理:
关于拖拽的基础,可以参考这篇文章,讲得非常不错。
http://www.sohotx.com/mzk/index.php/1007/ArticleContent/298.html
其实原理很简单,就是把绑定三个事件:onmousedown , onmousemove , onmouseup。
在鼠标点下时(onmousedown)把元素的坐标设置为鼠标的坐标,并把 position 设置为绝对坐标。
在鼠标移动时(onmousemove)改变元素坐标。
在鼠标弹起时(onmouseup)取消绑定的事件,并做后续操作。
下面是关于仿 google 个性化主页拖拽效果的一个 Demo (需包含 prototype)。
总共有四个文件:
   
[*]google_drag.html   
[*]prototype.js   
[*]通用拖拽函数 drag.js   
[*]仿 google 个性化主页的拖拽 google_drag.js
google_drag.html 中最后几行中有个初始化拖拽函数
<div class="hl-surround">   
[*]window.onload = function(){initDrag();}
页: [1]
查看完整版本: JavaScript Google IG Drag Demo(转)