JQuery sortable 효과 코드 를 따라 하 는 것 은 잘못 되 었 지만 볼 만하 다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>
JQuery sortable
</title>
<style type="text/css">
ul
{
width :200px;
list-style-type:none;
margin:0px;
padding:0px;
}
li
{
height: 100px; width: 202px
}
</style>
<script type="text/javascript">
var sortableDoubleUl=
{
offsetYInsertDiv:document.all?-10:-3,
srcUL:false,
leftUL:"leftUL",
rightUL:"rightUL",
moveableUL:false,
moveCounter:-1,
srcLI:false,
srcNextSibling:false,
leftPosOfLeftUL:false,
widthOfLeftUL:false,
leftPosOfRightUL:false,
widthOfRightUL:false,
insertDiv:false,
insertAsFirstNode:false,
descElement:false,
timer:10,
init:function()
{
this.leftUL = document.getElementById(this.leftUL);//<ul id="arrangableNodes">
this.rightUL= document.getElementById(this.rightUL);//<ul id="ul2">
var moveableUL= document.createElement('UL');
var moveableDiv=document.createElement("DIV");
moveableDiv.appendChild(moveableUL);
moveableDiv.style.position="absolute";
document.body.appendChild(moveableDiv);
this.moveableUL =moveableUL;
var insertDiv=document.createElement("DIV");
insertDiv.style.position="absolute";
insertDiv.style.display="none";
document.body.appendChild(insertDiv);
insertDiv.innerHTML="<img src='../images/insert.gif'/>";
this.insertDiv =insertDiv;
this.leftPosOfLeftUL =this.getAbsoluteLeftPos(this.leftUL);
this.leftPosOfRightUL=this.getAbsoluteLeftPos(this.rightUL);
this.insertDiv.style.left = this.leftPosOfLeftUL - 5 + 'px';
this.widthOfLeftUL= this.leftUL.offsetWidth;
this.widthOfRightUL=this.rightUL.offsetWidth;
var leftLi =this.leftUL.getElementsByTagName('LI');
for(var i=0;i<leftLi.length;i++)
{
leftLi[i].onmousedown = this.initMoveNode;
//
leftLi[i].onselectstart = this.cancelEvent;
}
var rightLi =this.rightUL.getElementsByTagName('LI');
for(var i=1;i<rightLi.length-1;i++)
{
rightLi[i].onmousedown = this.initMoveNode;
//
rightLi[i].onselectstart = this.cancelEvent;
}
document.documentElement.onmouseup =this.NodeStopMove;
document.documentElement.onmousemove =this.NodeMove;
document.documentElement.onselectstart = this.cancelEvent;
},
cancelEvent:function (){return false},//
getAbsoluteTopPos:function(srcObj)//
{
var returnValue = srcObj.offsetTop;
while((srcObj = srcObj.offsetParent) != null)
{
returnValue += srcObj.offsetTop;
}
return returnValue;
},
getAbsoluteLeftPos:function(srcObj)//
{
// position relative absolute body
var returnValue = srcObj.offsetLeft;
while((srcObj = srcObj.offsetParent) != null)
{
returnValue += srcObj.offsetLeft;
}
return returnValue;
},
initMoveNode:function(e)// LI LI
{
//clearMovableDiv();
if(document.all)
{
e = event;
}
// 0
sortableDoubleUl.moveCounter=0;
sortableDoubleUl.srcLI=this;
sortableDoubleUl.srcUL=this.parentNode;
if(this.nextSibling)
sortableDoubleUl.srcNextSibling =this.nextSibling;
else sortableDoubleUl.srcNextSibling = false;
sortableDoubleUl.moveNodeByTimer();
sortableDoubleUl.moveableUL.parentNode.style.left = e.clientX + 'px';
sortableDoubleUl.moveableUL.parentNode.style.top = e.clientY + 'px';
return false;
},
moveNodeByTimer:function ()
{
if(this.moveCounter>=0 && this.moveCounter<10)
{
this.moveCounter = this.moveCounter +1;
setTimeout('sortableDoubleUl.moveNodeByTimer()',this.timer);
}
if(this.moveCounter>=10)
{
this.moveableUL.appendChild(this.srcLI);
}
},
NodeMove:function(e)
{
if(document.all)e = event;
//
if(sortableDoubleUl.moveCounter<10)return;
if(document.all && sortableDoubleUl.moveCounter>=10 && e.button!=1 && navigator.userAgent.indexOf('Opera')==-1){
alert(" && ");
sortableDoubleUl.NodeStopMove();
}
// UL
sortableDoubleUl.moveableUL.parentNode.style.left = e.clientX + 'px';
sortableDoubleUl.moveableUL.parentNode.style.top = e.clientY + 'px';
// Y
var tmpY = e.clientY;
var tmpX = e.clientX;
sortableDoubleUl.insertDiv.style.display='none';
sortableDoubleUl.descElement = false;
//window.status=tmpX+":"+tmpY+"ul1left:"+leftPosArrangableNodes+"|"+(leftPosArrangableNodes + widthArrangableNodes)+"ul2left:"+leftPosArrangableNodes2+"|"+(leftPosArrangableNodes2+widthArrangableNodes2);
if(tmpX>sortableDoubleUl.leftPosOfLeftUL&&tmpX<(sortableDoubleUl.leftPosOfLeftUL +sortableDoubleUl.widthOfLeftUL))
{
var leftLI =sortableDoubleUl.leftUL.getElementsByTagName('LI');
sortableDoubleUl.insertDiv.style.left = (sortableDoubleUl.leftPosOfLeftUL + sortableDoubleUl.offsetYInsertDiv) + 'px';
for(var i=0;i<leftLI.length;i++)
{
// LI TOP
var topPos =sortableDoubleUl.getAbsoluteTopPos(leftLI[i]);
// LI
var tmpHeight = leftLI[i].offsetHeight;
if(i==0)
{
if(tmpY<=topPos && tmpY>=topPos-5)
{
sortableDoubleUl.insertDiv.style.top = (topPos +sortableDoubleUl.offsetYInsertDiv) + 'px';
sortableDoubleUl.insertDiv.style.display = 'block';
sortableDoubleUl.descElement = leftLI[i];
sortableDoubleUl.insertAsFirstNode = true;
return;
}
}
if(tmpY>=topPos && tmpY<=(topPos+tmpHeight))
{
sortableDoubleUl.insertDiv.style.top = (topPos+tmpHeight +sortableDoubleUl.offsetYInsertDiv) + 'px';
sortableDoubleUl.insertDiv.style.display = 'block';
sortableDoubleUl.insertAsFirstNode = leftLI[i];
sortableDoubleUl.descElement = leftLI[i];
insertAsFirstNode = false;
return;
}
}
}
else if(tmpX>sortableDoubleUl.leftPosOfRightUL&&tmpX<(sortableDoubleUl.leftPosOfRightUL +sortableDoubleUl.widthOfRightUL))
{
var rightLI =sortableDoubleUl.rightUL.getElementsByTagName('LI');
sortableDoubleUl.insertDiv.style.left =(sortableDoubleUl.leftPosOfRightUL+sortableDoubleUl.offsetYInsertDiv) + 'px';
for(var i=0;i<rightLI.length;i++)
{
// LI TOP
var topPos =sortableDoubleUl.getAbsoluteTopPos(rightLI[i]);
// LI
var tmpHeight = rightLI[i].offsetHeight;
if(i==0)
{
if(tmpY<=topPos && tmpY>=topPos-5)
{
sortableDoubleUl.insertDiv.style.top = (topPos +sortableDoubleUl.offsetYInsertDiv) + 'px';
sortableDoubleUl.insertDiv.style.display = 'block';
sortableDoubleUl.descElement = rightLI[i];
sortableDoubleUl.insertAsFirstNode = true;
return;
}
}
if(tmpY>=topPos && tmpY<=(topPos+tmpHeight))
{
sortableDoubleUl.insertDiv.style.top = (topPos+tmpHeight +sortableDoubleUl.offsetYInsertDiv) + 'px';
sortableDoubleUl.insertDiv.style.display = 'block';
sortableDoubleUl.descElement = rightLI[i];
sortableDoubleUl.insertAsFirstNode = false;
return;
}
}
}
else
{
return;
}
},
ClearMoveNode:function()
{
this.descElement = false;
if(sortableDoubleUl.moveableUL.getElementsByTagName('LI').length>0)
{
if(sortableDoubleUl.srcNextSibling)
this.srcUL.insertBefore(sortableDoubleUl.srcLI,sortableDoubleUl.srcNextSibling);
else sortableDoubleUl.srcUL.appendChild(sortableDoubleUl.srcLI);
}
},
NodeStopMove:function(e)
{
sortableDoubleUl.moveCounter = -1;
sortableDoubleUl.insertDiv.style.display='none';
//
if(sortableDoubleUl.descElement)
{
var parentUL=sortableDoubleUl.descElement.parentNode;
var li = parentUL.getElementsByTagName('LI');
if(sortableDoubleUl.descElement==li[0] && sortableDoubleUl.insertAsFirstNode)
{
if(parentUL==sortableDoubleUl.rightUL)
{
alert(" ")
sortableDoubleUl.ClearMoveNode();
}
else
{
parentUL.insertBefore(sortableDoubleUl.srcLI,sortableDoubleUl.descElement);
}
}
else
{
if(sortableDoubleUl.descElement.nextSibling)
{
parentUL.insertBefore(sortableDoubleUl.srcLI,sortableDoubleUl.descElement.nextSibling);
}
else
{
if(parentUL==sortableDoubleUl.rightUL)
{
sortableDoubleUl.ClearMoveNode();
alert(" ")
}
else
{
parentUL.appendChild(sortableDoubleUl.srcLI);
}
}
}
}
else
{
//
alert(" ");
sortableDoubleUl.ClearMoveNode();
}
}
};
</script>
</head>
<body>
<h1>
Arrange the nodes below</h1>
<table style="border:#ccc 1px solid;">
<tr>
<td style="width:2000px;border:#ccc 1px solid;">
<input id="Text1" style="width:500px; height:300px;" type="text" />
sfsfa
</td>
<td style="width:400px; border:#ccc 1px solid;">
<div>
<div style="padding: 5px">
<ul id="leftUL" style="height:500px; overflow:auto;">
<li id="node1">
<img src="imagePre/0004.gif" style="height: 55px; width: 202px" />
</li>
<li id="node2"> <img src="imagePre/0004.gif" style="height: 55px; width: 202px" /></li>
<li id="node3"> <img src="imagePre/0004.gif" style="height: 55px; width: 202px" /></li>
<li id="node4"> <img src="imagePre/0004.gif" style="height: 55px; width: 202px" /></li>
<li id="node5"> <img src="imagePre/0004.gif" style="height: 55px; width: 202px" /></li>
<li id="node6"> <img src="imagePre/0004.gif" style="height: 55px; width: 202px" /></li>
</ul>
</div>
</div>
</td>
<td style="width:400px;width:400px; border:#ccc 1px solid;">
<ul id="rightUL" style="height:500px; overflow:auto;">
<li id="Li1">
<div>
n11</div>
</li>
<li id="Li2">n12</li>
<li id="Li3">n13</li>
<li id="Li4">n14</li>
<li id="Li5">n15</li>
<li id="Li6">n16</li>
</ul>
</td>
</tr>
</table>
</form>
<div align="center">
:QQ:492006183
MSN:[email protected]
</div>
<script type="text/javascript">
sortableDoubleUl.init()
</script>
</body>
</html>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Laravel】 Sortable을 사용하여 쉽게 정렬 기능을 구현데이터 일람 화면에서 소트 기능을 붙이고 싶다. 좋아, JavaScript를 사용해 소고 그리고~...라고 엄청 귀찮아! 라는 것이 있었으므로, 정렬 기능이 간단하게 구현할 수 있는 패키지를 소개합니다. OS Win...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.