1、需求

  因为项目中要做一个可以移动、旋转和放缩具有合成图片的功能,例如:

剑可以随意移动,然后把位移、旋转角度和放缩值传给后台进行合成。

2、解决方案

网上搜到手势插件AlloyFinger,https://github.com/AlloyTeam/AlloyFinger

首先安装AlloyFinger:npm install alloyfinger

然后在Vue文件里面引用:import AlloyFinger from 'alloyfinger'

使用方法:

mounted() {
this.getData();
this.requireList = document.getElementsByClassName('required');
let swordEle = document.getElementsByClassName('swordPic')[0];
let bwidth, bheight, swidth, sheight;
Transform(swordEle);
var initScale = 1;
var af = new AlloyFinger(swordEle, {
touchStart: function () {
console.log('touchStart')
},
touchMove: function (evt) {
swordEle.style.translateX += evt.deltaX;
swordEle.style.translateY += evt.deltaY;
evt.preventDefault();
},
touchEnd: function () {
console.log('end')
console.log(swordEle.style.transform)
},
touchCancel: function () {
console.log('cancel')
},
multipointStart: function () {
initScale = swordEle.scaleX;
},
multipointEnd: function () {
},
tap: function () {
},
doubleTap: function () {
},
longTap: function () {
},
singleTap: function () {
},
rotate: function (evt) {
swordEle.rotateZ += evt.angle;
},
pinch: function (evt) {
swordEle.scaleX = swordEle.scaleY = initScale * evt.scale;
},
pressMove: function (evt) {
let widthDiff = bwidth - swidth;
let heightDiff = bheight - sheight;
console.log('diff' + widthDiff + ' ' + heightDiff)
console.log('translateX:' + swordEle.translateX + '' + swordEle.translateY )
if (((evt.deltaX>0)&&(swordEle.translateX >= widthDiff))||((evt.deltaY>0)&&(swordEle.translateY >= heightDiff))||((swordEle.translateX<0)&&((evt.deltaX<0)))||((swordEle.translateY<0)&&((evt.deltaY<0)))) {
console.log('越界')
} else {
swordEle.translateX += evt.deltaX;
swordEle.translateY += evt.deltaY;
} console.log('pressmve:' + swordEle.translateX)
console.log('pressmve:' + swordEle.translateY)
},
swipe: function (evt) {
// console.log("swipe" + evt.direction);
}
});
document.getElementById('coverPic').onload = function () {
bwidth = this.width;
bheight = this.height;
console.log(bwidth + ' ' + bheight)
if (document.body.scrollHeight - document.body.clientHeight > 20) {
document.body.scrollTop = document.body.scrollHeight;
}
}
document.getElementById('swordEle').onload = function () {
swidth = this.width;
sheight = this.height;
console.log(swidth + ' ' + sheight)
}
},

vue手势解决方案的更多相关文章

  1. nginx部署vue项目 解决方案

    给前端同事部署了web项目之后,访问发现除了index.html可以访问,其他的路径使用了“伪静态”.比如访问:http://localhost:8081/user/login,访问即报404错误,这 ...

  2. 超小Web手势库AlloyFinger原理

    目前AlloyFinger作为腾讯手机QQ web手势解决方案,在各大项目中都发挥着作用. 感兴趣的同学可以去Github看看:https://github.com/AlloyTeam/AlloyFi ...

  3. 超小Web手势库AlloyFinger原理(转载)

    目前AlloyFinger作为腾讯手机QQ web手势解决方案,在各大项目中都发挥着作用. 感兴趣的同学可以去Github看看: https://github.com/AlloyTeam/AlloyF ...

  4. vue数据绑定数组,改变元素时不更新view问题

    关于这个问题,官网上说的很清楚官方文档  写个例子HTML<body> <div class="box"> <div v-for="aa i ...

  5. ASP.NET MVC+Vue.js实现联系人管理

    接触了一天vue.js,简单浏览了一本关于vue的电子书,就开始动手使用ASP.NET MVC和Vue.js开发一个联系人管理的小程序. 先看一下这个联系人管理的小程序的界面,也就是我们大概要实现什么 ...

  6. 1.vue和react的区别

    1.个人感觉Vue好用,react不咋地呀. 2.(网上搜的)Vue的解决方案适用于小型应用,但对于对于大型应用而言不太适合.

  7. 2017 年比较 Angular、React、Vue 三剑客(转载)

    为 web 应用选择 JavaScript 开发框架是一件很费脑筋的事.现如今 Angular 和 React 非常流行,并且最近出现的新贵 VueJS 同样博得了很多人的关注.更重要的是,这只是一些 ...

  8. React的世界观及与Vue之比较

    写在前面:本文谈论的是主观的个人感受,不追求立场的“客观.公正”,因此我下面所说的很可能是错的,欢迎交流指正. 我学习前端时,跟大部分beginner一样,学的第一个框架是Vue,入职后也一直写Vue ...

  9. vue要求更新3.0-》使用axios的时候出现错误

    要求更新 使用axios报错 - Running completion hooks...error: 'options' is defined but never used (no-unused-va ...

随机推荐

  1. AjaxPro怎么用

    AjaxPro是首家支持以各种方式通过javascript访问服务端.net的免费库,类似于SAJAX.它能把Javascript请求发送到.NET方法,服务端传回给Javascript,甚至包括串行 ...

  2. python循环解码base64

    第一次写博客,都不知道该如何下手,写的不是很好,还望各位大佬不要喷我. 先来介绍一下base64: Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打 ...

  3. try catch finally 与continue的使用

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. 在windows搭建react

    1.安装必须的软件 1.Python 2    注意勾选 Add python.exe to Path,选项,这样就可以在安装完成后,不用手动去添加环境变量    安装完,打开cmd.exe,输入py ...

  5. oracle的SQL语句中的(+)是干什么用的?

    Oracle中的(+) 是外连接,如果在等号的左边就是左连接 和如果在等号的右边就是右连接 和left join ,right join 比较相似.....where sn (+) ='5620030 ...

  6. VM新安装centos7无法连接网络的问题

    https://blog.csdn.net/u012110719/article/details/42264601 https://blog.csdn.net/kexiaoling/article/d ...

  7. jQuery返回顶部代码

    页面较长时,使用返回顶部按钮比较方便,在电商中必备操作.下面自己制作一个js文件,totop.js,把它直接引用到需要的网页中即可. $(function () { $("body" ...

  8. asp.net mvc4使用log4.net 日志功能

    对于网站来讲,不能把异常信息显示给用户,异常信息只能记录到日志,出了问题把日志文件发给开发人员,就能知道问题所在. 下面演示网站 出错后自动添加出错日志的实例 (1)新建一个WebApplicatio ...

  9. MD5 十六进制加密

    MD5的加密方法很多,今天说下MD5的十六进制加密···先贴方法···· class Program { static void Main(string[] args) { //202cb962ac5 ...

  10. ural1297 求最长回文子串 | 后缀数组

    #include<cstdio> #include<algorithm> #include<cstring> #define N 20005 using names ...