茄子在线看片免费人成视频,午夜福利精品a在线观看,国产高清自产拍在线观看,久久综合久久狠狠综合

    <s id="ddbnn"></s>
  • <sub id="ddbnn"><ol id="ddbnn"></ol></sub>

  • <legend id="ddbnn"></legend><s id="ddbnn"></s>

    基于zepto.js簡單實現(xiàn)上傳圖片
    來源:易賢網(wǎng) 閱讀:3950 次 日期:2016-07-18 16:37:03
    溫馨提示:易賢網(wǎng)小編為您整理了“基于zepto.js簡單實現(xiàn)上傳圖片”,方便廣大網(wǎng)友查閱!

    這篇文章主要介紹了基于zepto.js簡單實現(xiàn)上傳圖片的相關(guān)資料,需要的朋友可以參考下

    效果如下:

    名單

    html: 

    <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>

    .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:0; left:0; width:3rem; height:3rem; opacity:0;}

    .basicInfo .aboutPic{ margin-bottom:.5rem; line-height:1.5rem; }

    js: 

    var img_arr = new Array();

     //相關(guān)圖片

     $(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 = '';

     });

     //刪除相關(guān)圖片

     $(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, //當(dāng)前圖片對象

     * cutWid:'', //裁剪尺寸

     * quality:0.6, //圖片質(zhì)量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

      };

      //成功后的回調(diào)

      obj.success(result);

     };

     };

    以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助

    更多信息請查看網(wǎng)絡(luò)編程
    易賢網(wǎng)手機網(wǎng)站地址:基于zepto.js簡單實現(xiàn)上傳圖片
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2026上岸·考公考編培訓(xùn)報班

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)