Directly to the code, the main focus has been commented in the code
Code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>untitled page</title>
<link rel= "Stylesheet" type= text/css "href=". /resources/css/ext-all.css "/>
<script type= "Text/javascript" src= ". /adapter/ext/ext-base.js "></script>
<script type= "Text/javascript" src= ". /ext-all-debug.js "></script>
<script type= "Text/javascript" src= ". /build/locale/ext-lang-zh_cn.js "></script>
<style type= "Text/css" >
body{font-size:12px;margin:10px;}
. Block {
BORDER:1PX Red Solid;
height:80px;
margin-top:50px;
padding:20px 0 0 20px;
Clear:both;
}
. Item {
border:1px #000 Solid;
margin-right:10px;
width:60px;
height:40px;
Text-align:center;
padding-top:20px;
Color:white;
Float:left;
Cursor:pointer;
}
</style>
<body>
<script type= "Text/javascript" >
Ext.onready (function () {
var proxy = new Ext.dd.DDProxy ("proxy"); This sentence can build a casually dragged Dongdong, magic Bar
(ExtJS Drag components are divided into two categories, ddproxy is the thing to drag, and Ddtarget is a drag can be thrown into the target container area)
The following set up three drag source Dropsource (inherited from Ddproxy can view official documents) and indicate GRUOP as DD
var proxy_red = new Ext.dd.DragSource (' proxy_red ', {group: ' DD '});
var proxy_green = new Ext.dd.DragSource (' Proxy_green ', {group: ' DD '});
var proxy_black = new Ext.dd.DragSource (' Proxy_black ', {group: ' DD '});
Drag-Completed Events
Proxy_red.afterdragdrop = function (target, E, id) {
var Destel = ext.get (ID);
var srcel = Ext.get (This.getel ());
var scolor = SrcEl.dom.id.split ('_') [1]; Drag the back part of the source ID, that is, the red behind the proxy_red.
DestEl.dom.style.backgroundColor = Scolor; Set the background color of the target ID
};
Proxy_green.afterdragdrop = Proxy_red.afterdragdrop; Assigning the same event handler to other drag sources
Proxy_black.afterdragdrop = Proxy_red.afterdragdrop;
var target = new Ext.dd.DDTarget (' target ', ' DD '); Create the drag target area where the DD is the same as the group:dd of the drag source above
Only Ddproxy/dragsource of the same group will be accepted)
});
</script>
<div>
<div id= "proxy_red" class= "item" style= "Background:red" >Red</div>
<div id= "Proxy_green" class= "item" style= "Background:green" >Green</div>
<div id= "Proxy_black" class= "item" style= "Background:black" >Black</div>
<div id= "proxy" class= "item" style= "Color:black" > I can <br/> casually drag </div>
</div>
<div id= "Target" class= "block" > Drag the color swatch above me to try </div>
</body>