【发布时间】: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