feat:paragraph selection when clicked three times

This commit is contained in:
Hufe921
2022-10-07 21:02:32 +08:00
parent 360fe73b29
commit 11204e772f
2 changed files with 63 additions and 1 deletions
+21
View File
@@ -66,4 +66,25 @@ export function downloadFile(href: string, fileName: string) {
a.href = href
a.download = fileName
a.click()
}
export function threeClick(dom: HTMLElement, fn: (evt: MouseEvent) => any) {
nClickEvent(3, dom, fn)
}
function nClickEvent(n: number, dom: HTMLElement, fn: (evt: MouseEvent) => any) {
let count = 0
let lastTime = 0
const handler = function (evt: MouseEvent) {
const currentTime = new Date().getTime()
count = (currentTime - lastTime < 300) ? count + 1 : 0
lastTime = new Date().getTime()
if (count >= n - 1) {
fn(evt)
count = 0
}
}
dom.addEventListener('click', handler)
}