Last active 1 month ago

Korbs's Avatar Korbs revised this gist 1 month ago. Go to revision

1 file changed, 57 insertions

README.md(file created)

@@ -0,0 +1,57 @@
1 + When building a custom video player, it will likely not work for end-users that have decided to disable JavaScript in their web browser. To get around this, it's best to add a fallback that'll allow them to switch over to the web browser's native player.
2 +
3 + To pull this off, we'll take advantage of the HTML tag known as `details` and `noscript`.
4 +
5 + ## Detect JavaScript is Disabled
6 +
7 + First, we need to tell if JavaScript is disabled, we can use the `noscript` tag. Anything used within a `noscript` tag is shown if JavaScript is not present.
8 +
9 + ```html
10 + <noscript>If you're seeing this, JavaScript is not enabled.</noscript>
11 + ```
12 +
13 + ## Toggle Button
14 +
15 + We'll create a button using the `details` tag that'll show the native video player.
16 +
17 + ```html
18 + <details>
19 + <summary>Show Native Player</summary>
20 + <video src="video.mp4"></video>
21 + </details>
22 + ```
23 +
24 + ## Full Example
25 +
26 + <p>Preview from Zorn v0.7 Development</p>
27 +
28 + ![Preview](https://ocean.sudovanilla.org/media/gifs/7fea948c65dc3a07.gif)
29 +
30 + Putting it altogether, with styling:
31 + ```html
32 +
33 + <noscript>
34 + <div style="background: #ffffff1f;padding: 12px 24px;font-size: 14px;aspect-ratio: 16/9;display: flex;justify-content: center;;border-radius: 12px; position:relative; display: flex; flex-direction: column;">
35 + <p>This web video player requires JavaScript in order to function properly. Please enable JavaScript in your web browser.</p>
36 + <details>
37 + <summary style="background: #00000082;width: max-content;border-radius: 3rem;padding: 12px 24px;margin: auto;cursor: pointer;">Use native player instead</summary>
38 + <video style="width: 100%" border-radius: 12px;" controls poster="poster.png" src="video.mp4"/>
39 + </details>
40 + <style>
41 + details[open] {
42 + position: absolute;
43 + top: 0px;
44 + left: 0px;
45 + width: 100%;
46 + summary {
47 + display: none;
48 + }
49 + video {
50 + pointer-events: all !important;
51 + }
52 + }
53 + </style>
54 + </div>
55 + <style>.yourcustomplayer {display: none}</style>
56 + </noscript>
57 + ```
Newer Older