技术干货

原创jquery拖拽排序图片上传插件实现(上)

2017-05-14  本文已影响0人  进击的大牛

从文章标题就能看出是一个专门做图片上传的插件,拖拽排序借鉴了网上的一个方法,融合到了本插件中,提供了一个专门捕捉图片绝对路径,链接,索引的方法,具体代码实现如下

html结构及其配置参数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>可拖拽的上传插件</title>
    <link rel="stylesheet" href="css/upload1.1.css" />
</head>
<body>

   <div class="div3" id="div3"></div>
   <a href="javascript:save();">保存</a>
   <script src="js/jquery-2.1.1.min.js"></script>
   <script src="js/TaoUpload-1.3.js"></script>
   <script>
       TaoTaoUpload({
           uId:"div3",
          // skin:"lightblue"  非必选参数(皮肤)
       });
       //取值操作,需要在控件下面获取
       function save(){
          console.log( jsonVal("div3"));
       }
   </script>
</body>
</html>

这里的这个方法用来上传数据

      //获取值操作
       function jsonVal(id){
           var array =[];
           var domObj = $("#"+id).find(".ul_Upload_nav").find(".li_for_Five");
           for(var i =0;i<domObj.length;i++){
               array.push({
                   src:domObj.eq(i).attr("data-src"),
                   href:domObj.eq(i).attr("data-href"),
                   index:domObj.eq(i).attr("data-index")
               })
           }
           return array;
       }

Css样式编写

body{ margin: 0;padding: 0;font-family: "微软雅黑";overflow: hidden;}
body,html{-webkit-text-size-adjust: none;width: 100%;height: 100%;}
*{text-decoration: none;list-style: none;}
img{border: 0px;}
ul,li,dl,dd,dt,p,ol,h1,h2,h3,h4,h5{font-size: 12px;font-weight: 100;padding: 0;margin: 0;}
.wrap{margin: 0 auto;}
.fl{float: left;}
.fr{float: right;}
.index{overflow: hidden;}
.clr{clear:both; height:0px; width:100%; font-size:1px; line-height:0px; visibility:hidden; overflow:hidden;}
.pointer{cursor:pointer;}
a,input,button{ outline:none; }
::-moz-focus-inner{border:0px;}
/*a:link {color:#0f0;text-decoration:none;}
a:visited {color: #FFFF00; text-decoration:none;}
a:hover {color: #00FF00; text-decoration:underline;}
a:active {color: #0000FF; text-decoration:underline;}*/
a{color: #000;}
.wrapper{clear: both;width: 100%;}
/**
插件重要样式
 */
.ul_Upload_nav{
    width: 100%;
    height: auto;
    float: left;
    margin-bottom: 20px;
}

.ul_Upload_nav li{
    width: 80px;
    height: 100px;
    background: url("../image/uploadsPic.png") no-repeat center center;
    background-size: 100% auto;
    float: left;
    color: #FFFFFF;
    line-height: 100px;
    text-align: center;
    position: relative;
    margin-right: 30px;
    border: 1px dashed #eeeeee;
    margin-top: 15px;
    margin-left: 20px;
}
.ul_Upload_nav li.li_for_Five{
    cursor: pointer;
    position: relative;

}
/* .ul_Upload_nav li.li_for_Five .zhezhao_upload_div{
     width: 15px;
     height: 15px;
     background:#000;
     color: #FFFFFF;
     text-align: center;
     line-height: 15px;
     position: absolute;
     right: -8px;
     top: -8px;
     border-radius: 50%;
     z-index: 8888;
 }*/
.ul_Upload_nav li.li_for_Five .zhezhao_upload_div{
    width: 100%;
    height: 25px;
    line-height: 25px;
    background:rgba(0,0,0,0.5);
    color: #FFFFFF;
    text-align: center;
    position: absolute;
    left: 0;
    bottom: 0;
    font-family: 'PingFangSC-Regular', 'PingFang SC';
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
}
.hide_file_input{
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
}
.a_Upload_btn_add{
    display:inline-block;
    width: 130px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background: lightblue;
    border-radius: 10px;
    margin-top: 0;
    text-decoration: none;
    color: #FFFFFF;
    margin-left: 20px;
}
/***
/ 弹层
 */
div.boxTanceng{
    width: 400px;
    height: auto;
    position: fixed;
    left: 50%;
    margin-left: -200px;
    top: 25%;
    background: #FFFFFF;
    border: 1px solid #ccc;
    display: none;
}
div.boxTanceng .boxTanceng_title{
    width: 100%;
    height: 48px;
    line-height: 48px;
    text-indent: 2em;
    background: #ccc;
    color: #FFFFFF;
}
div.boxTanceng .boxTanceng_body .tupian_upload_src{
    margin-top: 20px;
    font-family: 'PingFangSC-Regular', 'PingFang SC';
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    float: left;
}
div.boxTanceng .boxTanceng_body li:first-child{
    width: 100px;
    height: 100px;
    margin-left:70px ;
    float: left;

}
div.boxTanceng .boxTanceng_body .file_upladd_input_hides{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 80%;
    opacity: 0;
}
div.boxTanceng .boxTanceng_body li .tupian_upload_src_images{
    display: inline-block;
    width: 100px;
    height: 100px;
    border: 1px dashed #eeeeee;
    margin-left: 30px;margin-top: 10px;

}
div.boxTanceng .boxTanceng_body .tupian_upload_href{
    margin-top: 20px;
    font-family: 'PingFangSC-Regular', 'PingFang SC';
    font-style: normal;
    font-weight: 400;
    font-size: 14px;
    float: left;
}
div.boxTanceng .boxTanceng_body li:last-child input{
    width: 80%;
    height: 30px;
    border-radius: 5px;
    border: 1px solid #eeeeee;
    float: left;
    margin-top: 15px;
}
div.boxTanceng .boxTanceng_footer{
    margin-top: 80px;
}
div.boxTanceng .boxTanceng_footer .upload_btn{
    display: inline-block;
    width: 120px;
    height: 30px;
    margin: 10px 5px;
    text-align: center;
    line-height: 30px;
    color: #FFFFFF;
    background: #CCCCCC;
    text-decoration: none;
    border-radius: 15px;
}
div.boxTanceng .boxTanceng_footer .quxiao_upload_btn_noSave{
    margin-left: 50px;
    background: #eeeeee ;

}

总结

代码比较多,js部分放在下部里,喜欢的小伙伴可以看一下。

上一篇下一篇

猜你喜欢

热点阅读