<div class="codetitle"> <span><a style="CURSOR: pointer" data="28260" class="copybut" id="copybut28260" onclick="doCopy('code28260')"><u>코드 복사</u></a></span> 코드는 다음과 같습니다.</div> <div class="codebody" id="code28260"> <br><HTML> <br><HEAD> <br><TITLE>JS+CSS制作的DIV层最小化和随意拖拽排序功能</TITLE> <br><style type="text/css"> <br>body <br>{ <br>margin:10px; <br>} <br>#dragHelper <br>{ <br>position:absolute;/*重要*/ <br>border:2px dashed #000000; <br>background-color:#FFFFFF; <br>filter: alpha(opacity=30); <br>} <br>.normal <br>{ <br>position:absolute;/*重要*/ <br>width:300px; <br>#height:10px; <br>border:1px solid #666666; <br>background-color:#FFFFFF; <br>} <br>.over <br>{ <br>position:absolute;/*重要*/ <br>width:300px; <br>#height:10px; <br>border:1px solid #666666; <br>background-color:#f3f3f3; <br>filter: alpha(opacity=50); <br>} <br>.dragArea { <br>CURSOR: move; <br>} <br></style> <br></HEAD> <br><BODY oncontextmenu="window.event.returnValue=false"> <br><div id="dragHelper" style="display:none"></div> <br><div class="normal" overClass="over" dragClass="normal"> <br><table width="100%"> <br><tbody> <br><tr bgcolor="#CCCCCC" bar="yes"><td>百度</td><td dragArea="yes" class="dragArea">点此拖动</td><td><a href="#" onclick="openClose(this)">-</a> x</td></tr> <br><tr><td colspan="3">地址:http://www.baidu.com</td></tr> <br><tr><td colspan="3">关键字:</td></tr> <br><tr><td colspan="3">说明:</td></tr> <br></tbody> <br></table> <br></div> <br><div class="normal" overClass="over" dragClass="normal"> <br><table width="100%"> <br><tbody> <br><tr bgcolor="#CCCCCC" bar="yes"><td>新浪</td><td dragArea="yes" class="dragArea">........</td><td><a href="#" onclick="openClose(this)">-</a> x</td></tr> <br><tr><td colspan="3">地址:http://www.sina.com.cn</td></tr> <br><tr><td colspan="3">关键字:</td></tr> <br><tr><td colspan="3">说明:</td></tr> <br></tbody> <br></table> <br></div> <br><div class="normal" overClass="over" dragClass="normal"> <br><table width="100%"> <br><tbody> <br><tr bgcolor="#CCCCCC" bar="yes"><td>网页特效</td><td dragArea="yes" class="dragArea">........</td><td><a href="#" onclick="openClose(this)">-</a> x</td></tr> <br><tr><td colspan="3">地址:http://www.CsrCode.cn</td></tr> <br><tr><td colspan="3">关键字:</td></tr> <br><tr><td colspan="3">说明:</td></tr> <br></tbody> <br></table> <br></div> <br><div class="normal" overClass="over" dragClass="normal"> <br><table width="100%"> <br><tbody> <br><tr bgcolor="#CCCCCC" bar="yes"><td>七彩影视</td><td dragArea="yes" class="dragArea">........</td><td><a href="#" onclick="openClose(this)">-</a> x</td></tr> <br><tr><td colspan="3">地址:http://www.33567.cn</td></tr> <br><tr><td colspan="3">关键字:</td></tr> <br><tr><td colspan="3">说明:</td></tr> <br></tbody> <br></table> <br></div> <br></BODY> <br><SCRIPT LANGUAGE="JavaScript"> <br><!-- <BR>var dragObjs = [];//드래그할 수 있는 요소 배열<BR> var dragObjTops = []; <BR>var dragHelper = document.getElementById("dragHelper"); // 드래그 시 상자 위치 <BR>var dragObj = null; 🎜>var dragObjOffset = {left:0,top:0};//드래그 객체의 원래 위치<BR>var mouseInDragObjOffset = {x:0,y:0};//드래그 객체에서 마우스의 상대적 위치 드래그 객체 <BR>var initHeight = 40; <BR>Number.prototype.NaN0=function(){return isNaN(this)?0:this;} <BR>function getPosition(e){//절대 위치 가져오기 문서와 관련된 요소 <BR>var left = 0; <BR>var top = 0 <BR>while (e.offsetParent){ <BR>left = e.offsetLeft <BR>top = e.offsetTop; <BR>e = e .offsetParent; <BR>} <BR>left = e.offsetLeft; <BR>top = e.offsetTop <BR>return {x:left, y:top}; 🎜>function mouseCoords(ev ){//문서를 기준으로 마우스의 절대 위치를 가져옵니다. <BR>if(ev.pageX || ev.pageY){ <BR>return {x:ev.pageX, y:ev .pageY}; <BR>} <BR>return { <BR>x:ev.clientX document.body.scrollLeft - document.body.clientLeft, <BR>y:ev.clientY document.body.scrollTop - document.body .clientTop <BR>}; <BR> } <BR>function getMouseOffset(target, ev){//요소를 기준으로 마우스의 상대 위치를 가져옵니다. <BR>ev = ev || var elementPos = getPosition(target); <BR>var mousePos = mouseCoords(ev); <BR>return {x:mousePos.x - elementPos.x, y:mousePos.y - elementPos.y} <BR>function mouseDown(ev){ <BR>ev = ev || window.event; <BR>target = ev.srcElement || ev.target; <BR>if(dragObj)<BR>return; } <BR>var dragArea = false; <BR>if( target.getAttribute("dragArea")){ <BR>dragArea = true; <BR>} <BR>while(!target.getAttribute("isDragObj")) { <BR>if(target.tagName=="HTML" ) <BR>break; <BR>target = target.parentNode; <BR>} <BR>if(dragArea && target.getAttribute("isDragObj")){ <BR>dragObj = target; <BR>//Rewrite 현재 개체를 최상위 수준에 유지하는 것이 목적입니다. <BR>document.body.removeChild(dragObj) <BR>document.body.appendChild(dragObj); 🎜>//드래그 개체의 원래 위치 기록<BR>dragObjOffset.left = dragObj.style.left; <BR>dragObjOffset.top = dragObj.className = dragObj.getAttribute(" overClass"); <BR>//드래그 개체 Position<BR>mouseInDragObjOffset = getMouseOffset(dragObj, ev); <BR>dragHelper.style.left = dragObj.style.left; <BR> dragHelper.style.top = dragObj.style.top; <BR>dragHelper.style.width = dragObj.offsetWidth; <BR>dragHelper.style.height = dragHelper.style.display = ""; <BR>//alert(dragObj.offsetWidth ":" dragObj.clientWidth); <BR>} <BR>} <BR>function mouseUp(ev){ <BR>ev = ev || target = ev.srcElement || ev.target; <BR>if(dragObj){ <BR>dragObj.style.left = dragHelper.style.top = dragHelper.style.top; 🎜>dragHelper.style.display = "none"; <BR>dragObj.className = dragObj.getAttribute("dragClass"); <BR>dragObj = null <BR>} <BR>} <BR>function mouseMove(ev ){ <BR>ev = ev || window.event; <BR>if( dragObj) { <BR>var mousePos = mouseCoords(ev) <BR>/*dragHelper.style.left = <BR>dragHelper.style.top = dragObjOffset.top; <BR>dragHelper.style.width = dragObj.offsetWidth; <BR>dragHelper.style.height = dragObj.offsetHeight; / <BR>var windowWidth = document.body.offsetWidth;//창 너비<BR>var windowHeight = document.body.offsetHeight;//창 높이<BR>//드래그 개체는 현재 위치에 있어야 합니다<BR> var dragObjLeft = mouseInDragObjOffset.x; <BR>var dragObjTop = mousePos.y - mouseInDragObjOffset.y; <BR>//판단 추가, 그렇지 않으면 드래그 개체가 브라우저 창 밖으로 드래그됩니다. <BR>if( dragObjLeft >= 0 && dragObjLeft <= windowWidth - dragObj.offsetWidth - 20) <BR>dragObj.style .left = dragObjLeft; <BR>if(dragObjTop >=0) <br>dragObj.style.top = dragObjTop ; <br>repaint(); <br>} <br>} <br>//객체 복제<br>function cloneObject(srcObj, destObj){ <br>destObj = srcObj.cloneNode(true); <br>function makeDraggable(element){ <br>element.setAttribute("isDragObj", "y") ; <br>} <br>function repaint(){ <br>for(i=0; i<dragObjs. length; i ){ <BR>if(dragObjs[i] == dragObj){ <BR>dragObjPos = i; <BR>dragObjs[i] = dragHelper; <BR>} <BR>} 🎜>if(dragObjPos>0 &&parseInt(dragObj.style.top)<parseInt(dragObjs[dragObjPos- 1].style.top)){ <BR>dragObjs[dragObjPos] = dragObjs[dragObjPos-1] <BR>> dragObjPos 1].style.top)){ <BR>dragObjs[dragObjPos] = dragObjs[dragObjPos 1]; <BR>dragObjs[dragObjPos 1] = dragHelper; <BR>dragObjPos 1 <BR>} <BR> PaintDragObjs(); <BR>dragObjs[dragObjPos] = dragObj; <BR>} <BR>function PaintDragObj s( ){ <BR>var h = 40; i ){ <BR>dragObjs[i].style.left = 20; <BR>dragObjs[i].style.top = h <BR>h = dragObjs[i].offsetHeight 10; >}<BR>함수 openClose(obj){ <BR>obj.innerHTML = obj.innerHTML=="-"?" ":"-"; <BR>while(obj.tagName != "TBODY"){ <BR>obj = obj.parentNode; <BR>} <BR>for(i=0; i<obj.childNodes.length; i ){ <BR>if(obj.childNodes[i].nodeName == "#text" <BR>|| obj. childNodes[i].getAttribute("bar")){ 계속; } <BR>obj.childNodes[i].style.display=obj.childNodes[i].style.display==""?"none":""; <BR>} <BR>paintDragObjs(); <BR>} <BR>document.onmousedown = mouseDown; <BR>document.onmouseup = mouseUp; <BR>document.onmousemove = mouseMove; <BR>window.onload = function(){ <BR>var objs = document.getElementsByTagName("Div"); <BR>for(i=0; i<objs.length; i ){ <BR>var item = objs.item(i); <BR>//if(i==1)item.style.height=150; <BR>if(item.getAttribute("overClass")){ <BR>makeDraggable(item); <BR>dragObjs.push(item); <BR>item.style.left = 20; <BR>item.style.top = initHeight; <BR>dragObjTops.push(initHeight); <BR>initHeight = item.offsetHeight 10; <BR>} <BR>} <BR>// dragHelper = document.createElement('DIV'); <BR>// dragHelper.style.cssText = '위치:절대;표시:없음;'; <BR>// document.body.appendChild(dragHelper); <BR>} <BR>//--> <br></SCRIPT> <br></HTML> <br> </div>