上传图片(基于zepto.js)
效果如下:

<div class="otherPic">
<div id="showOtherImage"></div>
<span class="pull-left position_relative" id="openIdCardImg">
<span class="icon color-blue addPic"></span>
<input type="file" class="yy_inputFile" id="other_inputFile" name="reasonImg" />
</span>
</div>
html
.basicInfo .item{ padding:.5rem .5rem 0; border-top:.3rem solid #eeeeee;}
.basicInfo li{ overflow:hidden; margin-bottom:.5rem;line-height:2.1rem; border-bottom:1px solid #e3e3e3;}
.basicInfo li:last-child{ border-bottom:none;}
.basicInfo input[type="text"]{ height:2rem; line-height:2rem;}
.basicInfo textarea{ height:8rem; line-height:1.5rem;}
.basicInfo .otherPic{ min-height:3rem;}
.basicInfo .otherPic .addPic{ height:3rem; line-height:3rem; font-size:3rem; margin-bottom:.5rem;}
.basicInfo .otherPic img{ margin:0 .5rem .5rem 0; width:3rem; height:3rem; vertical-align:top; border:1px solid #ddd;}
.basicInfo .yy_inputFile{ position:absolute; top:; left:; width:3rem; height:3rem; opacity:;}
.basicInfo .aboutPic{ margin-bottom:.5rem; line-height:1.5rem; }
js:
var img_arr = new Array();
//相关图片
$(page).on('change','#other_inputFile',function () {
$(this).resizeImage({
that:this,
cutWid:'',
quality:0.6,
limitWid:710,
success:function (data) {
var len = $('#showOtherImage').find('img').size();
img_arr[len] = data.base64;
var img = '<div class="position_relative display-inlineBlock" style="float:left;">' +
'<img src="' + img_arr[len] + '">' +
'<span class="icon deletedImages" sid="' +len+ '" id="other_img_'+len+'"></span>'+
'</div>';
$('#showOtherImage').append(img);
if(img_arr.length == 9){
$('#openIdCardImg').hide();
return false;
}
}
});
this.value = '';
}); //删除相关图片
$(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="other_img_' +i+ '"></span>'+
'</div>';
$('#showOtherImage').append(img);
} if(img_arr.length < 9){
$('#openIdCardImg').show();
}else{
$('#openIdCardImg').hide();
}
}); /*
* 裁剪图片
* $(id).resizeImage({
* that:this, //当前图片对象
* cutWid:'', //裁剪尺寸
* quality:0.6, //图片质量0~1
* limitWid:400, //最小宽度
* success:function (data) {
* do something...
* }
* })
*
* */
$.fn.resizeImage = function (obj) {
var file = obj.that.files[0];
var URL = window.URL || window.webkitURL;
var blob = URL.createObjectURL(file);
var base64; 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, 0, 0, w, h); // 生成base64
base64 = canvas.toDataURL('image/jpeg', obj.quality || 0.8);
var result = {
base64:base64
}; //成功后的回调
obj.success(result);
};
};
上传图片(基于zepto.js)的更多相关文章
- 加减号改变input[type=number]的数值,基于[zepto.js]
通过点击加减号可以更改input的数值,样式如下图: 具体的html代码如下: <div class="xh-lxx-cart-count1"> <span cl ...
- 相册弹窗(基于zepto.js)
//放大图片 $(page).on('click','.popupImage img',function () { var that = $(this); that.popupImage({ this ...
- 省市选择(基于zepto.js)
效果如下: <div class="clList overflow-h mt75"> <select class="pull-left cl-35 se ...
- zepto.js 处理Touch事件(实例)
处理Touch事件能让你了解到用户的每一根手指的位置,在touch事件触发的时候产生,可以通过touch event handler的event对象取到,如果基于zepto.js开发,一般是通过eve ...
- zepto.js swipe实现触屏tab菜单
今天我们来说下zepto.js,有兴趣的朋友可以先进这个网站“http://zeptojs.com/” ,这个可以说是手机里的jquery,但是它取消了hover,加上了swipe及tap这两个触屏功 ...
- zepto.js 处理Touch事件
处 理Touch事件能让你了解到用户的每一根手指的位置,在touch事件触发的时候产生,可以通过touch event handler的event对象取到,如果基于zepto.js开发,一般是通过ev ...
- 怎么使用zepto.js的tap事件引起的探索
前言: 在使用zepto.js之前,你首先要知道它是什么?为什么要使用它?以及它和jquery有什么区别? ①:简单来说zepto是一个轻量级的针对现代高级浏览器的JavaScript库, 它与j ...
- zepto.js的touch模块
touch库实现了什么和引入背景 touch模块是基于zepto.js的. click事件在移动端上会有 300ms 的延迟,同时因为需要 长按 , 双触击 等富交互,所以我们通常都会引入类似 ze ...
- Zepto.js touch,tap增加 touch模块深入分析
1. touch库实现了什么和引入背景 click事件在移动端上会有 300ms 的延迟,同时因为需要 长按 , 双触击 等富交互,所以我们通常都会引入类似 zepto 这样的库.zepto 中tou ...
随机推荐
- 使用命令xrandr设置当前系统的显示分辨率及显示的旋转脚本
/********************************************************************* * Author : Samson * Date ...
- 架构师书单 2nd Edition--转载
作者:江南白衣,原文出处: http://blog.csdn.net/calvinxiu/archive/2007/03/06/1522032.aspx,转载请保留. 为了2007年的目标,列了下面待 ...
- Eclipse对printf()不能输出到控制台的解决方法
方案1: 在main 语句中加一条 setbuf(stdout,NULL); 这个即可. 在ecplise下使用cdt开发c程序,发现运行后终端没有输出,停止后会输出,通过在main中添加 setbu ...
- ASP.NET 之 检测到在集成的托管管道模式下不适用的ASP.NET设置
将ASP.NET程序从IIS6移植到IIS7后,调试运行可能提示以下错误: HTTP 错误 500.23 - Internal Server Error 检测到在集成的托管管道模式下不适用的 ASP. ...
- C#动态引用DLL的方法
C#编程中,使用dll调用是经常的事,这样做的好处是非常多的,比如把某些功能封装到一个dll中,然后主程序动态调用这个dll. 废话不多说,举例说明如下. 首先,我们需要封装一个dll,vs2008下 ...
- Python 替换字符串
string类型是不可变的,因此不能采用直接赋值的方式.比如一个字符串 helloworld,想把o替换成z,那么只有先替换,然后再迭代. strings="helloworld" ...
- ASP.NET MVC and jqGrid 学习笔记 4-排序
排序(Sorting)分为两种:客户端排序和服务端排序 客户端排序的意思是把数据从数据库里一次性全部提取出来,然后在客户端进行排序,以后每次点击标题进行排序时,就不会给服务端传递请求了.这个“一次性” ...
- git workflows
https://www.atlassian.com/git/tutorials/comparing-workflows Comparing Workflows The array of possibl ...
- C#中,为什么结构体也可以设置构造函数?
结构体派生自ValueType,ValueType派生自Object,可访问Object的方法.结构体是一种缩小版的类.结构体不能继承.结构体总是有一个无参数的默认构造函数,不允许替换.结构体可指定字 ...
- c#导出Excel 使用EXCEL进程
private void exportExcel(string filename, string path,string title, List<ArchivedWcsTask> wcst ...