【问题标题】:Multi Touch is Not workig in Chrome多点触控在 Chrome 中不起作用
【发布时间】:2019-10-24 03:31:29
【问题描述】:

如果两个 div 同时被按下/点击,我需要运行一个函数。我厌倦了下面的代码,但它一个接一个地执行事件。 我得到了一个示例代码,它在移动设备中运行良好。但它在桌面 chrome 中不起作用。

https://github.com/mdn/dom-examples/blob/master/touchevents/Multi-touch_interaction.html

组件 HTML

  <div>
<div>
  <div (press)="leftDivMousedown($event)" (pressup)="leftDivMouseup($event)" ></div>

  <div (press)="rightDivMousedown($event)" (pressup)="rightDivMouseup($event)"></div>
</div>

组件类

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {

  private leftTouch: boolean = true;
  private rightTouch: boolean = false;

  leftDivMousedown(event) {
   this.leftTouch = true;    
    if (this.rightTouch) {
       console.log("bothclick");
     }
  }

  leftDivMouseup(event) {
    this.leftTouch = false;
  }

  rightDivMousedown(event) {
    this.rightTouch = true;
    if (this.leftTouch) {
     console.log("bothclick");
    }
  }

  rightDivMouseup(event) {  
    this.rightTouch = false;
  }

【问题讨论】:

    标签: angular typescript touch-event hammer.js


    【解决方案1】:

    您确定事件名称是 press 吗?也许用 touch 代替 press 我可以解决你的问题。

    https://www.w3schools.com/jsref/obj_touchevent.asp

    尝试使用 touchstart 代替 press,使用 touchend 代替 pressup。

    【讨论】:

    • 我也很累,但行为相同
    • 新闻事件与hammer.js有关
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    相关资源
    最近更新 更多