본문 바로가기

카테고리 없음

javascript 마우스로 객체 이동시키기

////////////////////////////////////////////////////////
///////////////drag
var dragapproved=false;
var x,y, temp1, temp2;
var dragobj = null;
var index = 0;
var clickflag = false;

function c_focus(obj){
obj.style.zIndex = index;
index++;
}
function drag_ready(obj){
if(clickflag)
return ;
dragobj = obj;
}
function drag_unready(obj){
if(clickflag)
return ;
dragobj = null;
}
function move(e) {
if(ie){
if (event.button==1 &&  dragapproved){
dragobj.style.pixelLeft = temp1+event.clientX-x;
dragobj.style.pixelTop = temp2+event.clientY-y;
return false;
}
}
else
{
if (e.which==1 &&  dragapproved){
dragobj.style.pixelLeft = temp1+e.clientX-x;
dragobj.style.pixelTop = temp2+e.clientY-y;
return false;
}
}
}

function drags(e){
if(!e) e = window.event;
if(dragobj != null)
{
dragobj.style.zIndex = index;
index++;
temp1 = dragobj.style.pixelLeft;
temp2 = dragobj.style.pixelTop;
x=e.clientX;
y=e.clientY;
dragapproved = true;
document.onmousemove=move;
}
clickflag = true;
}
document.onmousedown =drags;
document.onmouseup = function() { dragapproved=false; clickflag = false;};
document.onselectstart = function() { return false;};
//////////////////////////////////////////////////////////////////