欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序?qū)崿F(xiàn)電子簽名功能

 更新時間:2020年07月29日 14:52:53   作者:youqiting  
這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)電子簽名功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序?qū)崿F(xiàn)電子簽名的具體代碼,供大家參考,具體內(nèi)容如下

// XXXX.wxml
<view class="signName">
 <canvas class="canvas" id="canvas" canvas-id="canvas" disable-scroll="true" bindtouchstart="canvasStart"
  bindtouchmove="canvasMove" bindtouchend="canvasEnd" touchcancel="canvasEnd"
  binderror="canvasIdErrorCallback"></canvas>
 </view>
 <view class="CList flex">
 <view class="flex_item marginR20" >
  <view class="saveBtn" bindtap="uploadImg">上傳簽名</view>
 </view>
 <view class="flex_item">
  <view class="clearBtn" bindtap="cleardraw">清除簽名</view>
</view> 

js:

var context = null;// 使用 wx.createContext 獲取繪圖上下文 context
var isButtonDown = false;//是否在繪制中
var arrx = [];//動作橫坐標
var arry = [];//動作縱坐標
var arrz = [];//總做狀態(tài),標識按下到抬起的一個組合
var canvasw = 0;//畫布寬度
var canvash = 0;//畫布高度
Page({

 data: {
 },
 
 onLoad: function () {
  this.startCanvas();
 },
 /**
 * 以下 - 手寫簽名 / 上傳簽名
 */
 startCanvas: function () {//畫布初始化執(zhí)行
 var that = this;
 //獲取系統(tǒng)信息
 wx.getSystemInfo({
  success: function (res) {
  canvasw = res.windowWidth;
  canvash = res.windowHeight;
  that.setData({ canvasw: canvasw });
  that.setData({ canvash: canvash });
  }
 }); 
 this.initCanvas();
 this.cleardraw(); 
 },
 //初始化函數(shù)
 initCanvas: function () {
 context = wx.createCanvasContext('canvas');
 context.beginPath()
 context.fillStyle = 'rgba(255, 255, 255, 0)';
 context.setStrokeStyle('#000000');
 context.setLineWidth(4);
 context.setLineCap('round');
 context.setLineJoin('round');
 },
 canvasStart: function (event) {
 isButtonDown = true;
 arrz.push(0);
 arrx.push(event.changedTouches[0].x);
 arry.push(event.changedTouches[0].y);
 },
 canvasMove: function (event) {
 if (isButtonDown) {
  arrz.push(1);
  arrx.push(event.changedTouches[0].x);
  arry.push(event.changedTouches[0].y);
 }
 for (var i = 0; i < arrx.length; i++) {
  if (arrz[i] == 0) {
  context.moveTo(arrx[i], arry[i])
  } else {
  context.lineTo(arrx[i], arry[i])
  }
 }
 context.clearRect(0, 0, canvasw, canvash);
 context.setStrokeStyle('#000000');
 context.setLineWidth(4);
 context.setLineCap('round');
 context.setLineJoin('round');
 context.stroke();
 context.draw(false);
 },
 canvasEnd: function (event) {
 isButtonDown = false;
 },
 //清除畫布
 cleardraw: function () {
 arrx = [];
 arry = [];
 arrz = [];
 context.clearRect(0, 0, canvasw, canvash);
 context.draw(true);
 },
 uploadImg(){
 var that = this
 //生成圖片
 wx.canvasToTempFilePath({
  canvasId: 'canvas',
  //設置輸出圖片的寬高
  // destWidth:150, 
  // destHeight:150,
  // fileType:'jpg',
  quality:1.0,
  success: function (res) {
  console.log(res)
  // canvas圖片地址 res.tempFilePath
  },
  fail: function () {
  wx.showModal({
   title: '提示',
   content: 'canvas生成圖片失敗。微信當前版本不支持,請更新到最新版本!',
   showCancel: false
  });
  },
  complete: function () {}
 })
 },
})

為大家推薦現(xiàn)在關(guān)注度比較高的微信小程序教程一篇:《微信小程序開發(fā)教程》小編為大家精心整理的,希望喜歡。

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 分享JavaScript與Java中MD5使用兩個例子

    分享JavaScript與Java中MD5使用兩個例子

    這篇文章主要為大家分享了JavaScript與Java中MD5使用兩個例子,
    2015-12-12
  • ZeroClipboard.js使用一個flash復制多個文本框

    ZeroClipboard.js使用一個flash復制多個文本框

    這篇文章主要為大家詳細介紹了ZeroClipboard.js使用一個flash復制多個文本框,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • wordpress之js庫集合研究介紹

    wordpress之js庫集合研究介紹

    wordpress之js庫集合研究介紹...
    2007-08-08
  • php去掉json反斜杠的實例講解

    php去掉json反斜杠的實例講解

    在本篇文章里小編給大家整理了一篇關(guān)于php去掉json反斜杠的實例講解,有興趣的朋友們可以參考學習下。
    2021-10-10
  • js實現(xiàn)一個逐步遞增的數(shù)字動畫

    js實現(xiàn)一個逐步遞增的數(shù)字動畫

    可視化大屏項目使用最多的組件就是數(shù)字組件,本文主要介紹了js實現(xiàn)一個逐步遞增的數(shù)字動畫,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-12-12
  • ajax在js中和jQuery中的用法實例詳解

    ajax在js中和jQuery中的用法實例詳解

    Ajax被認為是(Asynchronous(異步) JavaScript And Xml的縮寫),現(xiàn)在允許瀏覽器與服務器通信而無須刷新當前頁面的技術(shù)都被叫做Ajax,下面這篇文章主要給大家介紹了關(guān)于ajax在js中和jQuery中的用法,需要的朋友可以參考下
    2021-08-08
  • javascript中的replace函數(shù)(帶注釋demo)

    javascript中的replace函數(shù)(帶注釋demo)

    在js中有兩個replace函數(shù) 一個是location.replace(url) 跳轉(zhuǎn)到一個新的url.一個string.replace("xx","yy") 替換字符串 返回一個新的字符串,該方法并不改變字符串本身。下面通過本文給大家介紹javascript中的replace函數(shù)
    2018-01-01
  • js遍歷json對象所有key及根據(jù)動態(tài)key獲取值的方法(必看)

    js遍歷json對象所有key及根據(jù)動態(tài)key獲取值的方法(必看)

    下面小編就為大家?guī)硪黄猨s遍歷json對象所有key及根據(jù)動態(tài)key獲取值的方法(必看)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • 鼠標拖動改變DIV等網(wǎng)頁元素的大小的實現(xiàn)方法

    鼠標拖動改變DIV等網(wǎng)頁元素的大小的實現(xiàn)方法

    下面小編就為大家?guī)硪黄髽送蟿痈淖僁IV等網(wǎng)頁元素的大小的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • 小程序如何寫動態(tài)標簽的實現(xiàn)方法

    小程序如何寫動態(tài)標簽的實現(xiàn)方法

    這篇文章主要介紹了小程序如何寫動態(tài)標簽的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-02-02

最新評論