|
復制代碼 代碼如下:
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這個例子暫告一段落,看看一些好玩的(演示):
復制代碼 代碼如下:
var correct = { opt0:"ans1", opt1:"ans2", opt2:"ans0" } // 正確答案
var answer = { opt0:"tmp0", opt1:"tmp1", opt2:"tmp2" } // 解答
// 主站蜘蛛池模板: 石楼县| 双辽市| 平江县| 四会市| 邵阳县| 苏尼特右旗| 禹城市| 驻马店市| 万源市| 嵊泗县| 顺平县| 汝南县| 清徐县| 观塘区| 麦盖提县| 汪清县| 三原县| 宁城县| 济阳县| 伊宁市| 洛宁县| 文山县| 读书| 红安县| 夏邑县| 乌兰察布市| 中江县| 无锡市| 阳高县| 甘洛县| 永仁县| 剑河县| 天门市| 睢宁县| 公安县| 开平市| 德令哈市| 清水河县| 汝城县| 金湖县| 南昌市|