-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
80 lines (67 loc) · 2.61 KB
/
index.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
76
77
78
79
80
document.addEventListener("DOMContentLoaded", function(event) {
// States
var isPlaying = false
var isFullScreen = false
// Create dom elements
var playFullScreenContent = document.createElement('div')
document.body.appendChild(playFullScreenContent)
var playPause = document.createElement('button')
var fullScreen = document.createElement('button')
var playBtn = new Image()
var fullScreenBtn = new Image()
// Set buttons images
playBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/play.svg'
fullScreenBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/fullscreen.svg'
// Play scroll
function pageScroll() {
if (isPlaying) {
playBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/pause.svg'
window.scrollBy(0,1)
scrolldelay = setTimeout(pageScroll, 30)
} else {
playBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/play.svg'
}
}
function toggleScroll () {
isPlaying = !isPlaying
pageScroll()
}
/* Fullscreen */
function toggleFullscreen () {
isFullScreen = !isFullScreen
fullScreenFunc()
}
function fullScreenFunc() {
if (isFullScreen === true) {
fullScreenBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/close.svg'
document.documentElement.webkitRequestFullscreen()
} else {
fullScreenBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/fullscreen.svg'
document.webkitExitFullscreen()
}
}
// Change fullscreen icon when close fullscreen with esc
document.addEventListener('webkitfullscreenchange', exitHandler)
function exitHandler() {
if (!document.webkitIsFullScreen) {
fullScreenBtn.src = 'https://res.cloudinary.com/dyw3e3f2c/image/upload/v1544757407/saveeit/fullscreen.svg'
}
}
setTimeout(() => {
// Set buttons styles
playFullScreenContent.setAttribute(
'style',
'position: fixed; width: 100px; height: 50px; bottom: 25px; right: 25px; background-color: #000; color: #FFF; z-index: 9999; display: flex; justify-content: center;'
)
playPause.setAttribute('style', 'padding: 0;')
fullScreen.setAttribute('style', 'padding: 0;')
// Add elements on DOM
playPause.appendChild(playBtn)
fullScreen.appendChild(fullScreenBtn)
playFullScreenContent.appendChild(playPause)
playFullScreenContent.appendChild(fullScreen)
// Event
playPause.addEventListener('click', toggleScroll)
fullScreen.addEventListener('click', toggleFullscreen)
}, 3000)
})