欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript dragable的Move對象

 更新時間:2009年08月05日 21:07:07   作者:  
一個dragable的Move對象,大家可以運(yùn)行下,測試看下效果。

[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]

其中比較重要的代碼:
復(fù)制代碼 代碼如下:

var Move = {
$: function(id){
return (typeof id == "object") ? id : document.getElementById(id);
},
pageX: function(elem){ //獲取目標(biāo)elem的X坐標(biāo)
return elem.offsetParent ? //如果能繼續(xù)得到上一個元素,增加當(dāng)前的偏移量并繼續(xù)向上遞歸
elem.offsetLeft + this.pageX(elem.offsetParent) : elem.offsetLeft;
},
pageY: function(elem){ //獲取目標(biāo)elem的Y坐標(biāo)
return elem.offsetParent ? elem.offsetTop + this.pageX(elem.offsetParent) : elem.offsetTop;
},
make: function(id){
var elem = this.$(id);
var oldXY = null;
var newXY = null;
var x = 0; //記錄初始化是目標(biāo)elem的x坐標(biāo)
var y = 0; //記錄初始化是目標(biāo)elem的y坐標(biāo)
var t = this;
elem.onmouseover = function(e){
this.style.cursor = "default";
}
elem.onmousedown = function(e){
e = e || window.event;
this.style.position = "absolute";
this.style.cursor = "move";
x = t.pageX(this);
y = t.pageY(this);
var that = this;
oldXY = {
x: e.clientX,
y: e.clientY
}; //獲取鼠標(biāo)在按下的時候的坐標(biāo)
document.onmousemove = function(e){
e = e || window.event;
newXY = {
x: e.clientX,
y: e.clientY
}; //獲取鼠標(biāo)在移動過程中的坐標(biāo)
that.style.left = (newXY.x - oldXY.x + x) + "px";
that.style.top = (newXY.y - oldXY.y + y) + "px";
that.style.zIndex = "100";
}
}
elem.onmouseup = function(e){
this.style.cursor = "default";
this.style.zIndex = "0";
document.onmousemove = function(e){ //在放開鼠標(biāo)的時候覆蓋掉mousemove事件函數(shù)
return;
}
}
}
}

相關(guān)文章

最新評論