效果如下:
html:
js:
//删除相关图片
$(page).on('click','.deletedImages',function () {
var sid = $(this).attr('sid');
img_arr.splice(sid,1);
$(this).parent().remove();
$('#showOtherImage').html('');
for( var i=0; i < img_arr.length; i++) {
var img = '<div class="position_relative display-inlineBlock" style="float:left;">' +
'<img src="' + img_arr[i] + '">' +
'<span class="icon deletedImages" sid="' +i+ '" id="otherimg' +i+ '">'+
'
if(img_arr.length < 9){
$('#openIdCardImg').show();
}else{
$('#openIdCardImg').hide();
}
});
/*
var img = new Image();
img.src = blob;
if(!/image\/\w+/.test(obj.that.files[0].type)){
$.toast("请上传图片!",1000);
return false;
}
img.onload = function() {
if(img.width < obj.limitWid){
$.toast('图片宽度不得小于'+ obj.limitWid +'px',1000);
return false;
}
var that = this;
//生成比例
var w,scale,h = that.height;
if(obj.cutWid == ''){
w = that.width;
}else{
w = obj.cutWid;
}
scale = w / h;
h = w / scale;
//生成canvas
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
$(canvas).attr({
width: w,height: h
});
ctx.drawImage(that,w,h);
// 生成base64
base64 = canvas.toDataURL('image/jpeg',obj.quality || 0.8);
var result = {
base64:base64
};
//成功后的回调
obj.success(result);
};
};