# 마우스로 끌어서 이동시킬수있는 drag

 

<script type='text/javascript'>
<!--
var ie=document.all;
var nn6=document.getElementById&&!document.all;
var isdrag=false;
var x,y;
var dobj;
function movemouse(e)
{
  if (isdrag)
  {
    dobj.style.left = nn6 ? tx + e.clientX - x : tx + event.clientX - x;
    dobj.style.top  = nn6 ? ty + e.clientY - y : ty + event.clientY - y;
    return false;
  }
}
function selectmouse(e)
{
  var fobj      = nn6 ? e.target : event.srcElement;
  var topelement = nn6 ? 'HTML' : 'BODY';
  while (fobj.tagName != topelement && fobj.className != 'dragme')
  {
    fobj = nn6 ? fobj.parentNode : fobj.parentElement;
  }
  if (fobj.className=='dragme')
  {
    isdrag = true;
    dobj = fobj;
    tx = parseInt(dobj.style.left+0);
    ty = parseInt(dobj.style.top+0);
    x = nn6 ? e.clientX : event.clientX;
    y = nn6 ? e.clientY : event.clientY;
    document.onmousemove=movemouse;
    return false;
  }
}
document.onmousedown=selectmouse;
document.onmouseup=new Function('isdrag=false');
//-->
</script>
<style>.dragme{position:relative;}</style>
</head>

<body leftmargin=0 topmargin=0 bgcolor=#dddddd style='cursor:arrow;'>


<img src='http://img.youtube.com/vi/uNwsbkJMF6g/mqdefault.jpg' border=0 class='dragme' ondblclick='window.close();' style='cursor:move'>
<img src='http://img.youtube.com/vi/z-KUyuVi6Yc/mqdefault.jpg' border=0 class='dragme' ondblclick='window.close();' style='cursor:move'>

 

# jquery


<script src="//code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script>
$(document).ready(function(){
 $( ".drag" ).draggable();
});
</script>

<div style='background-color:#FFFF00;width:300px;height:200px;' class='drag'>aaaaaa</div>

 

 

 

'html, script' 카테고리의 다른 글

마우스스타일  (0) 2017.04.12
마우스에 붙어다니는 레이어 소스  (0) 2017.04.12
스톱워치 소스  (0) 2017.04.12
현재시간 시계 스크립트  (0) 2017.04.12
간단한 계산기 스크립트 소스  (0) 2017.04.12




+ Recent posts