利用Dojo实现拖动(Drag and Drop)效果
来源:互联网 发布:sql统计每小时的数据 编辑:程序博客网 时间:2024/06/05 08:59
如今各种使用AJAX技术的站点都实现了Drag and Drop(拖动)效果,利用Dojo框架也可以很方便的实现,相比较其它框架,代码更少,且对浏览器的兼容性支持比较好。
先看一下效果,以下是51AJAX.com站点首页的效果,其中各个模块是可以任意拖动的:
如何来实现呢?以下是具体步骤。为简单起见,做了一个Drag and Drop的Demo页面:
以下是具体步骤:
1.html部分
要实现拖动,首先要有容器,其次要有可拖动的元素。在这里我们设置了三个Div作为容器,ID分别是container1,container2,container3,每个容器中各放置了一个Div作为可拖动元素,它们的class是divdrag。
2.javas cript代码
首先在头部加入对dojo.js的引用,然后根据获取class为divdrag的元素,把它们注册为dojo.dnd.HtmlDragSource 对象,再将container1,container2,container3注册为三个容器,且指定容器中的可拖动元素可以被拖动到的容器,以上事件封 装成一个函数,增加至window.onload事件中。
<script src="./dojo/dojo.js">
</script>
<script>
//引用以下两个dojo包
dojo.require("dojo.style");
dojo.require("dojo.dnd.*");
function init(){
//利用classname取到元素列表,将其注册为dojo.dnd.HtmlDragSour
var arr=dojo.html.getElementsByClass('divdrag')
for(var i=0;i<arr.length;i++){
var parentDiv=arr[i].parentNode.id
new dojo.dnd.HtmlDragSource(arr[i],parentDiv);
}
//定义容器
new dojo.dnd.HtmlDropTarget("container1", ["container1","container2","container3"]);
new dojo.dnd.HtmlDropTarget("container2", ["container1","container2","container3"]);
new dojo.dnd.HtmlDropTarget("container3", ["container1","container2","container3"]);
}
//增加到window.onload事件中
window.onload=function(){init();}
</script>
<html>
<header>
</header>
<body>
<table background="yellow" title="sw">
<tr>
<div id="container1">
<div class="divdrag"><h2>aaaa</h2></div>
</div>
</tr><tr>
<div id="container2">
<div class="divdrag"><h2>bbbb</h2></div>
</div>
</tr><tr>
<div id="container3">
<div class="divdrag"><h2>cccc</h2></div>
</div>
</tr>
</table>
</body>
</html>
- 利用Dojo实现拖动(Drag and Drop)效果
- 利用Dojo实现拖动(Drag and Drop)效果
- Android 用户界面ImageView拖动复制(Drag and Drop)
- 用DHTML实现drag and drop的效果
- 在.NET中实现窗体控件的内容拖拽效果(Drag-and-Drop)
- html5之拖放效果 (drag and drop)
- 使用ASP.NET Atlas实现拖放(Drag & Drop)效果
- VC实现文件管理器拖拽(Drag-and-Drop)
- VC实现文件管理器拖拽(Drag-and-Drop)
- 简单Drag and Drop事件实现
- 分享一个HTML5的drag and drop API实现的图片拖拽分组效果
- 分享一个HTML5的drag and drop API实现的图片拖拽分组效果
- 详解QT下拖动操作Drag-Drop的实现
- web拖动Drag&Drop原理
- [前端] H5 drag drop 拖动
- (翻译)拖拽(Drag and drop)
- Android 用户界面---拖放(Drag and Drop)
- Android 用户界面---拖放(Drag and Drop)
- BREW 数据库接口
- DOJO常用的验证函数
- 孙振耀撰文谈退休并畅谈人生- 结语
- 将Excel文件中的数据导入SQL数据库中
- 谈C#中编码Encoding
- 利用Dojo实现拖动(Drag and Drop)效果
- 怎样判断你的交际能力强弱
- Java接口和Java抽象类
- 艰难渗透源码销售站点
- modbus源代码
- java中常用词汇
- dojo data 接口详解
- Asp.net中的Form身份验证
- MySQL数据库命名及设计规范