复制代码 代码如下:
<!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="/UploadFiles/2021-04-02/0004.gif"></li>
<li id="node2"> <img src="/UploadFiles/2021-04-02/0004.gif"><li id="node3"> <img src="imagePre/0004.gif"><li id="node4"> <img src="/UploadFiles/2021-04-02/0004.gif"><li id="node5"> <img src="imagePre/0004.gif"><li id="node6"> <img src="/UploadFiles/2021-04-02/0004.gif"></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:zhang-lizhi@hotmail.com

</div>
<script type="text/javascript">

sortableDoubleUl.init()
</script>
</body>
</html>
标签:
JQuery,sortable

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
狼山资源网 Copyright www.pvsay.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。