<div class="codetitle"> <span><a style="CURSOR: pointer" data="48295" class="copybut" id="copybut48295" onclick="doCopy('code48295')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code48295"> <br>(function($){ <br>$.fn.lsMovePanel=function(){ <br>var id=this.attr("id"); <br>var X=Y=0; <br>var offsetX=offsetY=0;//绝对位置 <br>var OldIndex=0;///存储原始索引 <br>var Temp_Li="<li id='\"Temp_Li\"' style='\"background-color:#FFFFFF;border-color:#FF023C\"'>"; <br>var Move_obj;///当前拖动的对象 <br>$("#"+id+" li").each(function(i){ <br>$(this).attr("open","0"); <br>//鼠标点击 <br>$(this).bind("mousedown",function(){ <br>if(event.button==1 || event.button==0){$(this).attr("open","1");} <br>if($(this).attr("open")=="1"){ <br>$(this).css({ <br>cursor:"move", <br>opacity:"0.7" <br>}); <br>X=event.clientX; <br>Y=event.clientY; <br>offsetX=$(this).offset().left; <br>offsetY=$(this).offset().top; <br>OldIndex=$(this).index(); <br>$(this).css({ <br>position:"absolute", <br>left:offsetX, <br>top:offsetY <br>}); <br>$("#"+id+" li").each(function(i){ <br>if(i==OldIndex){ <br>$(this).after(Temp_Li); <br>} <br>}) <br>} <br>}); <br>//鼠标放开 <br>$(this).bind("mouseup",function(){ <br>if(event.button==1 || event.button==0){$(this).attr("open","0");} <br>if($(this).attr("open")=="0"){ <br>$("#Temp_Li").before($(this)); <br>$(this).animate({ <br>left:$("#Temp_Li").offset().left, <br>top:$("#Temp_Li").offset().top, <br>},300,function(){ <br>$("#Temp_Li").remove(); <br>$(this).css({ <br>cursor:"default", <br>opacity:"1", <br>position:"static" <br>}); <br>}); <br>$("#"+id+" li").each(function(i){ <br>$(this).css({ <br>"border-color":"#666666" <br>}); <br>}); <br>} <br>}); <br>//移动 <br>$(this).bind("mousemove",function(){ <br>if($(this).attr("open")=="1"){ <br>var current_X=current_Y=0; <br>current_X=offsetX+event.clientX-X; <br>current_Y=offsetY+event.clientY-Y; <br>$(this).css({ <br>position:"absolute", <br>left:current_X, <br>top:current_Y <br>}); <br>Move_obj=this; <br>$("#"+id+" li").each(function(i){ <br>if(i!=OldIndex && $(this).attr("id")!="Temp_Li"){ <br>var Deviation=0; <br>var Max_X=$(this).offset().left+$(this).width()-Deviation; <br>var Min_X=$(this).offset().left+Deviation; <br>var Max_Y=$(this).offset().top+$(this).height()-Deviation; <br>var Min_Y=$(this).offset().top+Deviation; <br>if((event.clientX Max_Y) && (event.clientY+$(Move_obj).height() > Min_Y) && (event.clientX > Min_X) && (event.clientY $(this).css({ <br>"border-color":"#FF7578" <br>}); <br>//判断覆盖对象索引值在前还是后 <br>if(OldIndex>$(this).index()){ <br>$("#Temp_Li").before($(this)); <br>$("#Temp_Li").remove(); <br>$(this).before(Temp_Li); <br>}else{ <br>$("#Temp_Li").after($(this)); <br>$("#Temp_Li").remove(); <br>$(this).after(Temp_Li); <br>} <br>}else{ <br>$(this).css({ <br>"border-color":"#666666" <br>}); <br>} <br>} <br>}) <br>} <br>}); <br>}); <br>} <br>})(jQuery); <br> </div> <br>调用例子: <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="40009" class="copybut" id="copybut40009" onclick="doCopy('code40009')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code40009"> <br> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <br><title></title> <br><style> <BR>#Panel{ <BR>width:630px; <BR>height:auto; <BR>padding:0px; <BR>} <BR>#Panel li{ <BR>float:left; <BR>list-style:none; <BR>width:300px; <BR>height:100px; <BR>margin:5px; <BR>background-color:#D9F1FF; <BR>border:1px dotted #666666; <BR>text-align:center; position:static; <BR>} <BR>*{ <BR>font-size:12px; <BR>} <BR></style> <br> <br><script src="http://demo.jb51.net/jslib/jquery/jquery-1.4.2.min.js"></script> <br><script src="http://demo.jb51.net/jslib/lsMovePanel.js"></script> <br> <br><div style="margin-left:100px;"> <br><ul id="Panel"> <br><li style="background-color:#3399FF"> <br><li style="background-color:#00CCFF"> <br><li style="background-color:#CC9900"> <br><li style="background-color:#FF6600"> <br><li style="background-color:#FFCC99"> <br> </ul> <br> </div> <br><script> <BR>$("#Panel").lsMovePanel(); <BR></script> <br> <br> <br> </div>