-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
75 lines (62 loc) · 1.8 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
let $button = document.querySelector(".wrapper>button")
let $wrapper = document.querySelector(".wrapper")
let Box = document.querySelector("#Box")
let popover = document.querySelector("#popover")
let dragging = false
let X
let Y
let ButtonSwitch = true
let checkIsMove = false
Box.addEventListener('mousedown', (e) => {
dragging = true
X = e.clientX
Y = e.clientY
})
document.addEventListener('mousemove', (e) => {
let moveX
let moveY
moveX = e.clientX - X
moveY = e.clientY - Y
if ((Math.abs(moveX) >= 2 || Math.abs(moveY) >= 2) && dragging) {
checkIsMove = true
}
var BoundingBox = Box.getBoundingClientRect()
var BoundingPopover = popover.getBoundingClientRect()
if (dragging === true) {
Box.style.transform = Box.style.transform +
`translate(${moveX}px,${moveY}px)`
X = e.clientX
Y = e.clientY
}
console.log(BoundingBox.right)
console.log(BoundingPopover.left)
})
document.addEventListener('mouseup', (e) => {
dragging = false
setTimeout(() => {
checkIsMove = false
}, 0)
})
$button.addEventListener('click', () => {
if (checkIsMove === true) { return }
if (ButtonSwitch === true) {
popover.style.display = "block"
Box.textContent = "点击关闭八卦"
ButtonSwitch = false
} else {
popover.style.display = "none"
Box.textContent = "点击开启八卦"
ButtonSwitch = true
}
let ClickDocument = function (e) {
popover.style.display = "none"
Box.textContent = "点击开启八卦"
ButtonSwitch = true
document.removeEventListener(
'click', ClickDocument)
}
document.addEventListener('click', ClickDocument)
})
$wrapper.addEventListener('click', (e) => {
e.stopPropagation()
})