Posted on 2007-05-08 12:28
G_G 閱讀(3892)
評論(5) 編輯 收藏 所屬分類:
javascript
問題:? 興趣
解決:?? div的 onclike ( this?)? 得到選擇?
????????????由 window.event 得到 鼠標 x y?
????????????由 this.style.top/left 改變 div 位置?
????????var?x,y;
????????function?mousedown(obj)
????????{
????????????obj.onmousemove?=?mousemove;
????????????obj.onmouseup?=?mouseup;
????????????
????????????oEvent?=?window.event???window.event?:?event;
????????????x?=?oEvent.clientX;
????????????y?=?oEvent.clientY;
????????}
????????function?mousemove()
????????{
????????????oEvent?=?window.event???window.event?:?event;
????????????var?_top?=?oEvent.clientY?-?y?+?parseInt(this.style.top)?+?"px"; // oEvent.clientY?-?y? 為div 上 移動的位置 再反映到 ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?? //parseInt(this.style.top)
????????????var?_left?=?oEvent.clientX?-?x?+?parseInt(this.style.left)?+"px";
????????????this.style.top?=?_top;
????????????this.style.left?=?_left;
????????????x?=??oEvent.clientX;
????????????y?=??oEvent.clientY
????????}
????????function?mouseup()
????????{
????????????this.onmousemove?=?null;
????????????this.onmouseup?=?null;
????????}
心得: 興趣決定一切