上传图片(基于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 ...
随机推荐
- iOS开发——数据持久化&使用NSUserDefaults来进行本地数据存储
使用NSUserDefaults来进行本地数据存储 NSUserDefaults适合存储轻量级的本地客户端数据,比如记住密码功能,要保存一个系统的用户名.密码.使用NSUserDefaults是首 ...
- 实例源码--Android旋转式菜单(效果很炫)
下载源码 技术要点: 1.旋转式菜单功能实现 2.动画的应用 3.自定义控件的使用 ...... 详细介绍: 1. 旋转式菜单功能实现 本套例子通过自定义布局与动画的综合使用,实现了旋转式菜单效果 ...
- MYSQL查询今天昨天本周本月等的数据
mysql查询本季度 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT *FROM表名WHERE TO_DAYS ...
- The 7 Stages Of Scaling Web Apps--reference
reference from:http://highscalability.com/7-stages-scaling-web-apps TUESDAY, SEPTEMBER 23, 2008 AT 4 ...
- IP101A芯片默认物理地址(PHY Adress)确定
转载:http://blog.csdn.net/ropai/article/details/6961157 根据IP101A的DataSheet,芯片的第9,10,12,13,15脚为PHYAD0~P ...
- 4D数据介绍
转自青椒炒蛋:http://www.smallleafs.com/article/35.aspx 4D数据包括DLG(数字线画地图).DEM(数字高程模型).DOM(数字正射影像地图).DRG(数字栅 ...
- 如何删除C/C++源代码中的注释
具体代码: #include <stdlib.h> #include <stdio.h> //删除注释 void commentFilter(FILE* sourceFi ...
- VB.net 字符串 分割 及 重新倒序组装
''' <summary> ''' split with ">>>>" , and inverted order ''' </summar ...
- [改善Java代码]推荐使用枚举定义常量
枚举和注解都是在Java1.5中引入的,虽然他们是后起之秀,但是功能不容小觑,枚举改变了常量的声明方式,注解耦合了数据和代码. 建议83:推荐使用枚举定义常量 一.分析 常量的声明是每一个项目中不可或 ...
- .NET微信支付(H5仅限公众号支付)
闲来无事,恰好有一个要用微信公众平台支付的功能,研究来研究去,就是要细心和多看腾讯提供的文档.当然有几个坑是很有必要说明一下的 公众号支付,这里统一叫H5支付,以下都是. 在做H5支付的时候,第一步就 ...