// 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。