欢迎光临,了解微信小程序开发,就上易用通!

小程序极速实战开发《二十六》canvas画布

发布:2018-01-25 16:22浏览: 来源:网络 作者:tianshu

组件说明:

canvas画布,你可以理解为有一张白布,你可以在画布上画出不同形状、颜色、粗细的图形。


组件用法:

小程序极速实战开发《二十六》canvas画布(图1)

 

wxml

  1. <canvas class="canvas1" canvas-id="canvas1" bindtouchstart="mytouchstart" bindtouchmove="mytouchmove" bindtouchend="mytouchend"></canvas>

js

  1. Page({
  2.   ...
  3.   mytouchstart: function(e){
  4.    console.log('touchstart')
  5.   },
  6.   mytouchmove: function(e){
  7.     console.log('touchmove')
  8.   },
  9.   mytouchend: function(e){
  10.     console.log('touchend')
  11.   }
  12.   ...
  13. })

wxss

  1. .canvas1{
  2.     background-color: #E0E0E0;
  3. }

主要属性:
属性
类型
描述
canvas-id String canvas组件唯一标识符
disable-scroll Boolean 当手指在canvas上移动时,是否允许页面下拉刷新和页面滚动
bindtouchstart EventHandle 绑定手指开始触摸事件
bindtouchmove EventHandle 绑定手指触摸移动事件
bindtouchend EventHandle 绑定手指触摸结束事件
bindtouchcancel EventHandle 绑定手指触摸意外中断事件,例如弹窗,来电
binderror EventHandle 当发生错误时触发 error 事件,detail = {errMsg: ‘something wrong’}

注:

  • canvas组件支持大部分事件类型,也支持catch开头非冒泡事件。
  • canvas组件默认默认宽度300px、高度225px。
  • 一个页面中canvas-id不能重复使用。
  • 请勿在scroll-view中使用canvas




免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。