-
Notifications
You must be signed in to change notification settings - Fork 9
/
index2.html
219 lines (192 loc) · 6.2 KB
/
index2.html
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<html>
<head>
<style>
body, html {
height: 100%;
width: 100%;
margin: 0;
}
.bg {
/* The image used */
background-image: url("image.png");
/* Full height */
height: 100%;
/* Center and scale the image nicely */
background-position: center;
background-repeat: no-repeat;
background-size: contain;
background-color: black;
}
/* Fullscreen Button
https://henryegloff.com/fullscreen-button/
------------------------------*/
#fullscreen-button {
position: absolute;
top: 15px;
right: 15px;
background: rgba(128,128,128,25);
border: 0;
width: 40px;
height: 40px;
border-radius: 50%;
box-sizing: border-box;
transition: transform .3s;
font-size: 0;
opacity: 1;
pointer-events: auto;
cursor: pointer;
}
#fullscreen-button:hover {
transform: scale(1.125);
}
#fullscreen-button span {
width: 4px;
height: 4px;
border-top: 2.5px solid #111; /* color */
border-left: 2.5px solid #111; /* color */
position: absolute;
outline: 1px solid transparent;
-webkit-backface-visibility: hidden;
transform: translateZ(0);
will-change: transform;
-webkit-perspective: 1000;
transition: .3s;
transition-delay: .75s;
}
#fullscreen-button span:nth-child(1) {
top: 11px;
left: 11px;
}
#fullscreen-button span:nth-child(2) {
top: 11px;
left: 22px;
transform: rotate(90deg);
}
#fullscreen-button span:nth-child(3) {
top: 22px;
left: 11px;
transform: rotate(-90deg);
}
#fullscreen-button span:nth-child(4) {
top: 22px;
left: 22px;
transform: rotate(-180deg);
}
/* Fullscreen True
------------------------------*/
[fullscreen] #fullscreen-button span:nth-child(1) {
top: 22px;
left: 22px;
}
[fullscreen] #fullscreen-button span:nth-child(2) {
top: 22px;
left: 11px;
}
[fullscreen] #fullscreen-button span:nth-child(3) {
top: 11px;
left: 22px;
}
[fullscreen] #fullscreen-button span:nth-child(4) {
top: 11px;
left: 11px;
}
/* Dark Style
------------------------------*/
[light-mode=dark] {
background: #111;
color: #fff;
}
[light-mode=dark] #fullscreen-button {
background: rgba(255,255,255,.05);
}
[light-mode=dark] #fullscreen-button span {
border-top: 2.5px solid #fff;
border-left: 2.5px solid #fff;
}
</style>
<script>
function check_fullscreen() {
console.log("check_fullscreen");
// Because users can exit & enter fullscreen by other methods
if (document.fullscreenElement || document.webkitIsFullScreen || document.mozFullScreen) {
if (!document.body.getAttribute("fullscreen")) {
console.log("Entering fullscreen after the fact");
document.body.setAttribute("fullscreen", 1);
}
} else {
if (document.body.getAttribute("fullscreen")) {
console.log("Exiting fullscreen after the fact");
document.body.removeAttribute("fullscreen");
}
}
}
function create_fullscreen_button() {
let fullscreen_button = document.createElement("button");
fullscreen_button.setAttribute('id', 'fullscreen-button');
fullscreen_button.addEventListener("click", toggle_fullscreen);
fullscreen_button.innerHTML = `
<span></span>
<span></span>
<span></span>
<span></span>
`;
// This needs to be on the fullscreen element since otherwise it will get
// occluded by it no matter the z-index
document.getElementById("canvas").appendChild(fullscreen_button);
setInterval(function(){ check_fullscreen();}, 2000);
}
function toggle_fullscreen() {
console.log("windows size", window.outerWidth, window.outerHeight, " devicepixelratio", window.devicePixelRatio);
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
let elementToFullscreen = document.getElementById("canvas");
// XXX See https://bugzilla.mozilla.org/show_bug.cgi?id=714809
elementToFullscreen = document.documentElement;
if (elementToFullscreen.requestFullscreen) {
elementToFullscreen.requestFullscreen()
} else if (elementToFullscreen.mozRequestFullScreen) {
elementToFullscreen.mozRequestFullScreen()
} else if (elementToFullscreen.webkitRequestFullscreen) {
elementToFullscreen.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT)
}
document.body.setAttribute("fullscreen", 1)
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen()
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen()
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen()
}
document.body.removeAttribute("fullscreen")
}
}
function onLoad() {
console.log("Installing fullscreen");
let elem = document.getElementById("canvas");
elem = document.documentElement;
// Fullscreen button
if (document.fullscreenEnabled || document.webkitFullscreenEnabled ||
document.msFullscreenEnabled ) {
create_fullscreen_button();
}
elem.addEventListener("dblclick", toggle_fullscreen);
setInterval( function() {
console.log("setInterval");
var imgUrl = "image.png?" + new Date().getTime();
var imgElement = new Image();
// Prevent flicker by loading the image in a dummy image first and
// setting to the background image
// Note this requires the debug pane to be closed, otherwise setting
// the background image will flicker the same
imgElement.onload = function() {
console.log("loaded " + this.src);
document.getElementById("canvas").style.backgroundImage = "url(" + this.src + ")";
}
imgElement.src = imgUrl;
}, 1000);
}
</script>
</head>
<body class="bg" onload="onLoad()" id="canvas">
</body>
</html>