【实例简介】
【实例截图】
【核心代码】
html5上传多个文件并添加水印body{font-size:12px;}
a{text-decoration:none;}
a,a:after{-webkit-transition:all 0.3s;-moz-transition:all 0.3s;transition:all 0.3s;}
a.btn i{display:block;width:100%;height:100%;position:relative;z-index:1;cursor:pointer;}
a.btn:after,input.btn:after{content:" ";position:absolute;z-index:0;display:block;width:0;left:50%;top:0;display:block;height:100%;}
a.btn:hover:after,input.btn:hover:after{width:100%;left:0;}
a.bg40b450,.bg40b450{background:#40b450;position:relative;}
a.bg40b450:hover:after{background:#63d072;}
.pac0{filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity:0;opacity:0;}
.uploadimg span{color:#999;margin-left:15px;}
.uploadimg span i{color:#fe8625;}
.uploadimg a{width:100px;height:36px;line-height:36px;display:inline-block;position:relative;overflow:hidden;text-align:center;vertical-align:middle;}
.uploadimg a i{color:#fff;font-style:normal;}
.uploadimg a input{font-size:100px;height:130%;width:200%;position:absolute;right:0;top:0;z-index:1;}
.uploadimg p img{margin-bottom:10px;width:80px;}
#pic div{height:98px;width:98px;line-height:98px;border:1px solid #e6e6e6;text-align:center;margin-top:10px;}
#pic p{float:left;position:relative;margin:10px 10px 10px 0;width:98px;height:98px;border:1px solid #e6e6e6;}
#pic p img{margin:0;width:98px;height:98px;}
#pic p a{position:absolute;left:0;bottom:0;width:100%;height:20px;line-height:20px;background:rgba(0,0,0,0.5);color:#fff;z-index:2;}
#pic p b{background:#fe8625;color:#fff;padding:0 5px;position:absolute;left:0;top:0;display:none;}
选择图片
最大上传1M的图片(格式png,gif,jpg)
function bindclick() {
//删除图片事件
$("#pic a.del").unbind();
$("#pic a.del").click(function () {
$(this).parent().remove();
});
}
// 每次上传总数
var uploadcount = 0;
$(function () {
//图片上传
$("#uploadfile").change(function () {
if($(this).val()!="")
upload($(this).attr("name"),1024,"Y");
});
});
//图片上传方法
//obj1传上传控件的name属性,maxlength上传图片大小kb单位,watermark上传的图片是否加水印
function upload(obj1,maxlength,watermark,w,h) {
$("#aspnetForm").ajaxSubmit({
url: 'uploadall.ashx?index=' obj1 '&maxlength=' maxlength '&watermark=' watermark '&_=' Math.random(),
beforeSubmit: function () {
},
success: function (data) {
var imglist = data.split("|");
var imghtml = "";
var cren = "";
var hascrent = $("#pic p.crently").length > 0 ? 1 : 0;
for (var i = 0; i < imglist.length; i ) {
if (imglist[i].indexOf("Upload/Images") != -1)
imghtml = '
默认图删除图片
';}
//上传总数统计
if($("#pic p").length==0)
uploadcount = $("#pic p").length $("#uploadfile")[0].files.length;
else
uploadcount = $("#uploadfile")[0].files.length;
$("#pic").append(imghtml);
//上传成功个数
crentcount = $("#pic p").length;
//上传失败个数
var failcount = uploadcount != crentcount ? "," parseInt(uploadcount - crentcount) "个文件上传失败" : "";
$("#filelength").html("选择了" uploadcount "文件,成功上传了" crentcount "文件" failcount);
bindclick();//绑定删除事件
}
});
}