레이어 팝업 드래그기능 넣기 질문입니다
본문
메인에 레이어 팝업이 뜨는것 드래그 기능 넣을수 있나요?
이것 저것 해봤는데 영 잘 안되네요.~~~
고수님들 부탁드립니다 ^^
팝업 차체를 드래그해서 옮기는 기능입니다
답변 4
<script type='text/javascript'>
var img_L = 0;
var img_T = 0;
var targetObj;
function getLeft(o){
return parseInt(o.style.left.replace('px', ''));
}
function getTop(o){
return parseInt(o.style.top.replace('px', ''));
}
// 이미지 움직이기
function moveDrag(e){
var e_obj = window.event? window.event : e;
var dmvx = parseInt(e_obj.clientX + img_L);
var dmvy = parseInt(e_obj.clientY + img_T);
targetObj.style.left = dmvx +"px";
targetObj.style.top = dmvy +"px";
return false;
}
// 드래그 시작
function startDrag(e, obj){
targetObj = obj;
var e_obj = window.event? window.event : e;
img_L = getLeft(obj) - e_obj.clientX;
img_T = getTop(obj) - e_obj.clientY;
document.onmousemove = moveDrag;
document.onmouseup = stopDrag;
if(e_obj.preventDefault)e_obj.preventDefault();
}
// 드래그 멈추기
function stopDrag(){
document.onmousemove = null;
document.onmouseup = null;
}
</script>
</body>
<div onmousedown='startDrag(event, this)'>
팝업내용
</div>
요렇게 적용하시면 되겠습니다.