栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

基于jquery的拖动布局插件

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于jquery的拖动布局插件

复制代码 代码如下:
(function($){
$.fn.lsMovePanel=function(){
var id=this.attr("id");
var X=Y=0;
var offsetX=offsetY=0;//绝对位置
var OldIndex=0;///存储原始索引
var Temp_Li="
  • ";
    var Move_obj;///当前拖动的对象
    $("#"+id+" li").each(function(i){
    $(this).attr("open","0");
    //鼠标点击
    $(this).bind("mousedown",function(){
    if(event.button==1 || event.button==0){$(this).attr("open","1");}
    if($(this).attr("open")=="1"){
    $(this).css({
    cursor:"move",
    opacity:"0.7"
    });
    X=event.clientX;
    Y=event.clientY;
    offsetX=$(this).offset().left;
    offsetY=$(this).offset().top;
    OldIndex=$(this).index();
    $(this).css({
    position:"absolute",
    left:offsetX,
    top:offsetY
    });
    $("#"+id+" li").each(function(i){
    if(i==OldIndex){
    $(this).after(Temp_Li);
    }
    })
    }
    });
    //鼠标放开
    $(this).bind("mouseup",function(){
    if(event.button==1 || event.button==0){$(this).attr("open","0");}
    if($(this).attr("open")=="0"){
    $("#Temp_Li").before($(this));
    $(this).animate({
    left:$("#Temp_Li").offset().left,
    top:$("#Temp_Li").offset().top,
    },300,function(){
    $("#Temp_Li").remove();
    $(this).css({
    cursor:"default",
    opacity:"1",
    position:"static"
    });
    });
    $("#"+id+" li").each(function(i){
    $(this).css({
    "border-color":"#666666"
    });
    });
    }
    });
    //移动
    $(this).bind("mousemove",function(){
    if($(this).attr("open")=="1"){
    var current_X=current_Y=0;
    current_X=offsetX+event.clientX-X;
    current_Y=offsetY+event.clientY-Y;
    $(this).css({
    position:"absolute",
    left:current_X,
    top:current_Y
    });
    Move_obj=this;
    $("#"+id+" li").each(function(i){
    if(i!=OldIndex && $(this).attr("id")!="Temp_Li"){
    var Deviation=0;
    var Max_X=$(this).offset().left+$(this).width()-Deviation;
    var Min_X=$(this).offset().left+Deviation;
    var Max_Y=$(this).offset().top+$(this).height()-Deviation;
    var Min_Y=$(this).offset().top+Deviation;
    if((event.clientX < Max_X) && (event.clientY+$(Move_obj).height() > Max_Y) && (event.clientY+$(Move_obj).height() > Min_Y) && (event.clientX > Min_X) && (event.clientY < Max_Y) ){
    $(this).css({
    "border-color":"#FF7578"
    });
    //判断覆盖对象索引值在前还是后
    if(OldIndex>$(this).index()){
    $("#Temp_Li").before($(this));
    $("#Temp_Li").remove();
    $(this).before(Temp_Li);
    }else{
    $("#Temp_Li").after($(this));
    $("#Temp_Li").remove();
    $(this).after(Temp_Li);
    }
    }else{
    $(this).css({
    "border-color":"#666666"
    });
    }
    }
    })
    }
    });
    });
    }
    })(jQuery);

    调用例子:
    复制代码 代码如下:






    #Panel{
    width:630px;
    height:auto;
    padding:0px;
    }
    #Panel li{
    float:left;
    list-style:none;
    width:300px;
    height:100px;
    margin:5px;
    background-color:#D9F1FF;
    border:1px dotted #666666;
    text-align:center; position:static;
    }
    *{
    font-size:12px;
    }

















    转载请注明:文章转载自 www.mshxw.com
    本文地址:https://www.mshxw.com/it/113530.html
    我们一直用心在做
    关于我们 文章归档 网站地图 联系我们

    版权所有 (c)2021-2022 MSHXW.COM

    ICP备案号:晋ICP备2021003244-6号