Vue+canvas实现移动端手写板步骤详解

这次给大家带来Vue+canvas实现移动端手写板步骤详解,Vue+canvas实现移动端手写板的注意事项有哪些,下面就是实战案例,一起来看一下。

 

Canvas画板 Vue+canvas实现移动端手写板步骤详解

var draw;var preHandler = function(e){e.preventDefault();}class Draw { constructor(el) { this.el = el this.canvas = document.getElementById(this.el) this.cxt = this.canvas.getContext('2d') this.stage_info = canvas.getBoundingClientRect() this.path = { beginX: 0, beginY: 0, endX: 0, endY: 0 } } init(btn) { var that = this; this.canvas.addEventListener('touchstart', function(event) { document.addEventListener('touchstart', preHandler, false); that.drawBegin(event) }) this.canvas.addEventListener('touchend', function(event) { document.addEventListener('touchend', preHandler, false); that.drawEnd() }) this.clear(btn) } drawBegin(e) { var that = this; window.getSelection() ? window.getSelection().removeAllRanges() : document.selection.empty() this.cxt.strokeStyle = "#000" this.cxt.beginPath() this.cxt.moveTo( e.changedTouches[0].clientX - this.stage_info.left, e.changedTouches[0].clientY - this.stage_info.top ) this.path.beginX = e.changedTouches[0].clientX - this.stage_info.left this.path.beginY = e.changedTouches[0].clientY - this.stage_info.top canvas.addEventListener("touchmove",function(){ that.drawing(event) }) } drawing(e) { this.cxt.lineTo( e.changedTouches[0].clientX - this.stage_info.left, e.changedTouches[0].clientY - this.stage_info.top ) this.path.endX = e.changedTouches[0].clientX - this.stage_info.left this.path.endY = e.changedTouches[0].clientY - this.stage_info.top this.cxt.stroke() } drawEnd() { document.removeEventListener('touchstart', preHandler, false); document.removeEventListener('touchend', preHandler, false); document.removeEventListener('touchmove', preHandler, false); //canvas.ontouchmove = canvas.ontouchend = null } clear(btn) { this.cxt.clearRect(0, 0, 300, 600) } save(){ return canvas.toDataURL("image/png") }}export default { data () { return { msg: 'Welcome to Your Vue.js App', val:true, url:"" } }, mounted() { draw=new Draw('canvas'); draw.init(); }, methods:{ clear:function(){ draw.clear(); }, save:function(){ var data=draw.save(); this.url = data; console.log(data) },   mutate(word) { this.$emit("input", word); },} } h1, h2 { font-weight: normal;}ul { list-style-type: none; padding: 0;}li { display: inline-block; margin: 0 10px;}a { color: #42b983;}#canvas { background: pink; cursor: default;}#keyword-box { margin: 10px 0;}

登录后复制

相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!

推荐阅读:

vue地区选择组件使用步骤详解

JS+CSS3实现鼠标与图片互动放大效果

以上就是Vue+canvas实现移动端手写板步骤详解的详细内容,更多请关注【创想鸟】其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。

发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2761974.html

(0)
上一篇 2025年3月8日 09:43:06
下一篇 2025年2月24日 17:16:05

AD推荐 黄金广告位招租... 更多推荐

相关推荐

  • Node.Js实现端口重用步骤详解

    这次给大家带来Node.Js实现端口重用步骤详解,Node.Js实现端口重用的注意事项有哪些,下面就是实战案例,一起来看一下。 起源,从官方实例中看多进程共用端口 const cluster = require(‘cluster’);con…

    编程技术 2025年3月8日
    200
  • vuex+localstorage动态监听storage步骤详解

    这次给大家带来vuex+localstorage动态监听storage步骤详解,vuex+localstorage动态监听storage步的注意事项有哪些,下面就是实战案例,一起来看一下。 分析:vue无法监听localstorage的变化…

    编程技术 2025年3月8日
    200
  • ES6实现全屏滚动插件步骤详解

    这次给大家带来ES6实现全屏滚动插件步骤详解,ES6实现全屏滚动插件使用的注意事项有哪些,下面就是实战案例,一起来看一下。 1)前面的话 现在已经有很多全屏滚动插件了,比如著名的 fullPage ,那为什么还要自己造轮子呢? 现有轮子有以…

    2025年3月8日
    200
  • vue-cli创建项目步骤详解

    这次给大家带来vue-cli创建项目步骤详解,vue-cli创建项目的注意事项有哪些,下面就是实战案例,一起来看一下。 使用npm 与vue-cli 构建vue 项目 第一步:安装运行环境(node与npm) nodeJ官网:http://…

    2025年3月8日 编程技术
    200
  • vue中模态对话框组件实现步骤详解

    这次给大家带来vue中模态对话框组件实现步骤详解,vue中模态对话框组件实现的注意事项有哪些,下面就是实战案例,一起来看一下。 写在前面 对话框是很常用的组件 , 在很多地方都会用到,一般我们可以使用自带的alert来弹出对话框,但是假如是…

    2025年3月8日
    200
  • vue绑定id从列表页跳转至详情页步骤详解

    这次给大家带来vue绑定id从列表页跳转至详情页步骤详解,vue绑定id从列表页跳转至详情页的注意事项有哪些,下面就是实战案例,一起来看一下。 1. 列表页:列表页带id跳转到详情页 详情页:把id传回到后台就可以获取到数据了 2.列表页跳…

    2025年3月8日 编程技术
    200
  • Vue项目中使用Vux安装配置步骤详解

    这次给大家带来Vue项目中使用Vux安装配置步骤详解,Vue项目中使用Vux安装配置的注意事项有哪些,下面就是实战案例,一起来看一下。 默认已安装vue环境 1.安装vux npm install vux –save-dev 2…

    2025年3月8日
    200
  • 调用缓存实现JS方法步骤详解

    这次给大家带来调用缓存实现JS方法步骤详解,调用缓存实现JS方法的注意事项有哪些,下面就是实战案例,一起来看一下。 1.什么是方法重载 方法重载是指在一个类中定义多个同名的方法,但要求每个方法具有不同的参数的类型或参数的个数。简而言之就是:…

    编程技术 2025年3月8日
    200
  • vue2.0+插件使用npm发布步骤详解

    这次给大家带来vue2.0+插件使用npm发布步骤详解,vue2.0+插件使用npm发布的注意事项有哪些,下面就是实战案例,一起来看一下。 此篇尽量详细,清楚的讲解vue插件的开发到npm的发布,想想将你自己做的东西展示给广大“网民”,心里…

    2025年3月8日 编程技术
    200
  • Vue实现PopupWindow组件使用步骤解析

    这次给大家带来Vue实现PopupWindow组件使用步骤解析,Vue实现PopupWindow组件使用的注意事项有哪些,下面就是实战案例,一起来看一下。 这段时间一直在学习前端技术来完成自己的小项目。在js方面就使用了Vue框架。由于在项…

    2025年3月8日
    200

发表回复

登录后才能评论