學習YUI.Ext第五日--做拖放Darg&Drop
2024-09-06 12:42:58
供稿:網友
拖放某個元素Darg&Drop是windows(視窗)問世時的一個重要特征?,F在我們要在瀏覽器里面實現,怎么做呢?先看看基本例子:
代碼如下:
YAHOO.example.DDApp = function() {
var dd;
return {
init2: function() {
// var dropzone =["dz"];
// for(i in dropzone){
// new YAHOO.util.DDTarget(dropzone[i]);
// };
var draggable =["dd_1","dd_2","dd_3"]; //數組存放DargDrop的ID
Draggable = function(id, sGroup) {
//建立DragDrop對象。這個必須由YAHOO.util.DragDrop的子類來調用
//Sets up the DragDrop object. Must be called in the constructor of any YAHOO.util.DragDrop subclass
this.init(id, sGroup);
}
Draggable.prototype = new YAHOO.util.DD(); //繼承父類
Draggable.prototype.startDrag = function(x, y) {
YAHOO.util.Dom.setStyle(this.getEl(), "opacity", 0.5);
}
Draggable.prototype.endDrag = function(e) { //拖放后返回原點
var draggable = this.getEl();
YAHOO.util.Dom.setStyle(draggable, "opacity", 1.0);
draggable.style.left = "0px";
draggable.style.top = "0px";
}
for(i in draggable){
new Draggable(draggable[i]);
}
}
}
} ();
注意的地方:
1.這里用了一個數組先收集好所有要DD(Darg&Drop,下同)的元素,再用for遍歷new new YAHOO.util.DD()對象,“捆綁”成一類具有相同屬性的對象:Draggable。
2.遇到一個無法入手的問題:
用YUI做Dragdrop,如果你的系統開clearType ,移動之后字體會發毛,估計ie內部render的問題 。本來打算用DDProxy代替,但一用DDProxy就無法繼承下去。
3.需手工加入xhtml的holder.
ok這個例子暫告一段落,看看一些好玩的(演示):