-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
75 lines (57 loc) · 2.34 KB
/
index.ts
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
const cameraEl = document.getElementById("polaroid-camera")!
const cameraImgEl = document.getElementById("polaroid-img")!
const polaroidPictureWrapperEl = document.getElementById("polaroid-picture-wrapper")!
const polaroidPictureEl = document.getElementById("polaroid-picture")!
const cameraImgAspect = cameraImgEl.clientWidth / cameraImgEl.clientHeight
const cameraBtn = document.createElement("button")
const flashOverlay = document.getElementById("flash-overlay")!
const audioEl = document.getElementById('camera-sound')! as HTMLAudioElement
cameraBtn.className = "cameraBtn"
document.body.appendChild(cameraBtn)
const targetCameraWidth = 500
cameraEl.style.width = targetCameraWidth + 'px'
cameraEl.style.height = (targetCameraWidth / cameraImgAspect) + 'px'
cameraImgEl.remove()
const setSizes = () => {
const cameraBounds = cameraEl.getBoundingClientRect()
polaroidPictureWrapperEl.style.left = cameraBounds.left + (targetCameraWidth * 0.11) + 'px'
polaroidPictureWrapperEl.style.top = cameraBounds.top + (targetCameraWidth * 0.74) + 'px'
polaroidPictureWrapperEl.style.width = (targetCameraWidth * 0.81) + 'px'
polaroidPictureWrapperEl.style.height = ((targetCameraWidth * 0.81) * 1.2) + 'px'
polaroidPictureEl.style.height = polaroidPictureWrapperEl.style.height
polaroidPictureEl.style.width = polaroidPictureWrapperEl.style.width
cameraBtn.style.width = (targetCameraWidth * 0.072) + 'px'
cameraBtn.style.height = (targetCameraWidth * 0.072) + 'px'
cameraBtn.style.top = cameraBounds.top + (targetCameraWidth * 0.287) + 'px'
cameraBtn.style.left = cameraBounds.left + (targetCameraWidth * 0.158) + 'px'
cameraEl.style.opacity = "1"
cameraBtn.style.opacity = "1"
polaroidPictureEl.style.opacity = "1"
}
setSizes()
window.addEventListener("resize", () => {
setSizes()
})
let active = false
const snap = () => {
if (active) return
console.log("Snap!")
active = true
polaroidPictureEl.classList.remove("open")
setTimeout(() => {
active = false
}, 8000)
audioEl.play();
setTimeout(() => {
flashOverlay.classList.add("active")
}, 100);
setTimeout(() => {
flashOverlay.classList.remove("active")
}, 500);
setTimeout(() => {
polaroidPictureEl.classList.add("open")
}, 1800);
}
cameraBtn.addEventListener("click", () => {
snap()
})