div 레이어 드래그 일반 이해하기 쉬운 버전

16131 단어 div
<html>
<style id="css">
body
{font-family:Verdana;font-size:11px;color:#333;}
#win
{position:absolute;left:100px;top:100px;width:200px;height:150px;border:1px solid #000;}
.title
{width:100%;background:#000;height:18px;color:#fff;cursor:hand;}
</style>
<script>
var x0=0,y0=0,x1=0,y1=0;
var moveable=false;
// ;
function startDrag(evt){
var dragObj=document.getElementById("win");
var evt = (evt) ? evt : ((window.event) ? window.event : "")
document.getElementById(
"title").setCapture();
var win = dragObj;
x0
= evt.clientX;
y0
= evt.clientY;
x1
= parseInt(win.offsetLeft);
y1
= parseInt(win.offsetTop);
moveable
= true;
}
// ;
function drag(evt){
if(moveable){
var evt = (evt) ? evt : ((window.event) ? window.event : "")
var dragObj=document.getElementById("win");
var win = dragObj;
document.getElementById(
"content").innerHTML= evt.clientX;
win.style.left
= x1 + evt.clientX - x0;
win.style.top
= y1 + evt.clientY - y0;
}
}
// ;
function stopDrag(obj){
if(moveable){
obj.releaseCapture();
moveable
= false;
}
}
</script>
<body>
, , . !
<div id="win">
<div class="title" id="title" onmousedown="startDrag(event)" onmouseup="stopDrag(this)" onmousemove="drag(event)"> 1</div>
<div id="content">
.<br>
, .<br>
</div>
</div>
</body>
</html>

좋은 웹페이지 즐겨찾기