-
Notifications
You must be signed in to change notification settings - Fork 0
/
zviewer.js
72 lines (61 loc) · 2.02 KB
/
zviewer.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
function zviewer(i) {
// Div
let div = document.createElement('div')
div.style.display = 'block'
div.style.position = 'fixed'
div.style.zIndex = 999
div.style.opacity = 0
div.style.top = 0
div.style.left = 0
div.style.width = '100%'
div.style.height = '100%'
div.style.cursor = 'pointer'
div.style.transitionDuration = '0.5s'
div.style.backdropFilter = 'brightness(0.5) blur(5px)'
document.body.appendChild(div)
// Img
let img = document.createElement('img')
img.src = i.src || i
img.style.opacity = 0
img.style.scale = 0.5
img.style.width = '100%'
img.style.height = '100%'
img.style.objectFit = 'contain'
img.style.transitionDuration = '0.5s'
div.appendChild(img)
// Spinner
let canvas = document.createElement('canvas')
canvas.width = 100
canvas.height = 100
canvas.style.position = 'fixed'
canvas.style.top = 'calc(50% - 50px)'
canvas.style.left = 'calc(50% - 50px)'
canvas.animate([{ scale: 0.5, filter: 'opacity(0)' }, { filter: 'opacity(1)' }, { scale: 1, filter: 'opacity(0)' }], { duration: 750, iterations: Infinity })
let spinner = canvas.getContext('2d')
spinner.beginPath()
spinner.arc(50, 50, 40, 0, 2 * Math.PI, false)
spinner.lineWidth = 8
spinner.strokeStyle = '#FFF'
spinner.stroke()
div.append(canvas)
img.addEventListener('load', () => {
img.style.opacity = 1
img.style.scale = 1
canvas.remove()
});
// Show animation
setTimeout(function () {
div.style.opacity = 1
document.body.style.overflow = 'hidden'
}, 1)
// Hide animation & remove
div.onclick = function () {
this.onclick = null
img.style.scale = 0.5
div.style.opacity = 0
img.pointerEvents = 'none'
div.pointerEvents = 'none'
document.body.style.removeProperty('overflow')
setTimeout(function () { div.remove() }, 500)
}
}