使用AlloyFinger插件实现div包括其子元素的双指缩放单指移动

该文章展示了如何在Vue.js项目中使用AlloyFinger库来处理div元素的触摸事件,如缩放(pinch)、移动(pressMove)。通过调整posX、posY和dis的数据属性,实现了元素的位置和缩放变换。
摘要由CSDN通过智能技术生成
npm install --save alloyfinger
 <div :class='["mapcontent", currMap.name]' 
       ref="pic"
         :style="{
        	 transform:
             'translate(' +
             posX +
             'px,' +
             posY +
             'px) translateZ(0px) scale(' +
             dis +
             ')',
         }">
         ...
 </div>
  
    import AlloyFinger from "alloyfinger";
	...
	data() {
            return {
               posX: 0,
               posY: 0,
               dis: 1
            };
        },
    ...
    mounted(){
   	 this.initControl();
    },
    methods: {
		initControl() {
			   let that = this;
			   let pic = this.$refs.pic;// 要操作的div
			   this.af = new AlloyFinger(pic, {
			       // rotate: function (evt) {
			       //   console.log("实现旋转");
			       //   that.angle += evt.angle;
			       // },
			       pinch: function (evt) {
			           console.log("实现缩放");
			           that.dis = evt.zoom > 1 ? evt.zoom : 1;
			       },
			       pressMove: function (evt) {
			           console.log("实现移动");
			           console.log(evt);
			           //   if(that.dis>1) {
			           that.posX += evt.deltaX;
			           that.posY += evt.deltaY;
			           //   }
			       },
			       // tap: function (evt) {
			       //   console.log("单击");
			       //   //点按触发
			       // },
			       // doubleTap: function (e) {
			       //   console.log("双击");
			       //   //双击屏幕触发
			       // },
			       // longTap: function (e) {
			       //   console.log("长按");
			       //   //长按屏幕750ms触发
			       // },
			       // swipe: function (e) {
			       //   //e.direction代表滑动的方向
			       //   console.log("swipe" + e.direction);
			       // },
			    });
			},
	}
	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值