We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
拖拽的时候会触发点击事件,所以得分清是拖拽还是点击
click
mouseDown
mouseUp
mouseMove
所以我们在mouseDown事件中记录鼠标的位置,在mouseUp 时比较此时的位置是否相同则可判断是点击还是拖拽。
html
<div cdkDrag (mousedown)="onMousedown($event)" (mouseup)="onMouseup($event)" > </div>
ts
dowmPosi = []; upPosi = [] onMousedown(event: MouseEvent){ const { pageX, pageY } = event; this.dowmPosi.push(pageX, pageY); } onMouseup(event: MouseEvent){ const { pageX, pageY } = event; this.upPosi.push(pageX, pageY) if(_.isEqual(this.dowmPosi, this.upPosi)){ // 这里去执行点击事件做的事情 } this.resetMouseFlag(); } resetMouseFlag(){ this.dowmPosi = []; this.upPosi = []; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
问题
拖拽的时候会触发点击事件,所以得分清是拖拽还是点击
原理介绍
click
,但是我们这里需要用mouseDown
和mouseUp
来实现mouseDown
、mouseMove
、mouseUp
所以我们在
mouseDown
事件中记录鼠标的位置,在mouseUp
时比较此时的位置是否相同则可判断是点击还是拖拽。html
ts
The text was updated successfully, but these errors were encountered: