最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript dragable的Move對(duì)象

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

[Ctrl+A 全選 注:引入外部Js需再刷新一下頁(yè)面才能執(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ù)得到上一個(gè)元素,增加當(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)在按下的時(shí)候的坐標(biāo)
document.onmousemove = function(e){
e = e || window.event;
newXY = {
x: e.clientX,
y: e.clientY
}; //獲取鼠標(biāo)在移動(dòng)過(guò)程中的坐標(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){ //在放開(kāi)鼠標(biāo)的時(shí)候覆蓋掉mousemove事件函數(shù)
return;
}
}
}
}

相關(guān)文章

最新評(píng)論

白朗县| 句容市| 辽宁省| 海原县| 惠水县| 灵台县| 信丰县| 苗栗市| 龙井市| 门头沟区| 怀集县| 建瓯市| 措美县| 南城县| 侯马市| 炎陵县| 维西| 来凤县| 山阴县| 武陟县| 丹棱县| 柳林县| 广饶县| 贵州省| 霍城县| 德惠市| 宝应县| 宜昌市| 河源市| 荔波县| 体育| 建昌县| 东乡| 瑞丽市| 孟州市| 邢台市| 日照市| 依安县| 合水县| 樟树市| 阜新|