video fullscreen on orientation change to landscape
This commit is contained in:
1 parent
30f48e1fc7
commit
4c7605156a
2 files changed
+57
-5
No files matched your search
@@ -9,6 +9,15 @@ export default defineConfig({
|
|||||||
title: "ko-grammar",
|
title: "ko-grammar",
|
||||||
description: "Korean grammar edited",
|
description: "Korean grammar edited",
|
||||||
lang: "ko-KR",
|
lang: "ko-KR",
|
||||||
|
head: [
|
||||||
|
[
|
||||||
|
"script",
|
||||||
|
{
|
||||||
|
async: "async",
|
||||||
|
src: "https://www.youtube.com/iframe_api",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
themeConfig: {
|
themeConfig: {
|
||||||
socialLinks: [
|
socialLinks: [
|
||||||
{ icon: "github", link: "https://git.polv.cc/polv/ko-grammar" },
|
{ icon: "github", link: "https://git.polv.cc/polv/ko-grammar" },
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="$style.container">
|
<div :class="$style.container">
|
||||||
<iframe
|
<iframe
|
||||||
|
ref="iframe"
|
||||||
:class="$style.iframe"
|
:class="$style.iframe"
|
||||||
width="100%"
|
width="100%"
|
||||||
height="100%"
|
height="100%"
|
||||||
:src="
|
:src="url.href"
|
||||||
`https://www.youtube.com/embed/${$props.id || 'videoseries'}` +
|
|
||||||
($props.list ? `?list=${$props.list}` : '')
|
|
||||||
"
|
|
||||||
:title="$props.title"
|
:title="$props.title"
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
allow="
|
allow="
|
||||||
@@ -28,11 +26,56 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
defineProps<{
|
import { onBeforeUnmount, onMounted, ref, useTemplateRef } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
id?: string;
|
id?: string;
|
||||||
list?: string;
|
list?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
|
const url = new URL(
|
||||||
|
`https://www.youtube.com/embed/${props.id || "videoseries"}`,
|
||||||
|
);
|
||||||
|
url.searchParams.set("enablejsapi", "1");
|
||||||
|
if (props.list) {
|
||||||
|
url.searchParams.set("list", props.list);
|
||||||
|
}
|
||||||
|
|
||||||
|
const iframe = useTemplateRef("iframe");
|
||||||
|
const player = ref();
|
||||||
|
|
||||||
|
function onOrientationChanged() {
|
||||||
|
if (player.value && iframe.value) {
|
||||||
|
if (
|
||||||
|
window.screen.orientation.type.startsWith("landscape") &&
|
||||||
|
player.value.getPlayerState() === 1
|
||||||
|
) {
|
||||||
|
iframe.value.requestFullscreen();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (document.fullscreenElement) {
|
||||||
|
document.exitFullscreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
const { YT } = window as any;
|
||||||
|
if (YT?.Player && iframe.value) {
|
||||||
|
player.value = new YT.Player(iframe.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.screen.orientation.addEventListener("change", onOrientationChanged);
|
||||||
|
});
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
window.screen.orientation.removeEventListener("change", onOrientationChanged);
|
||||||
|
if (document.fullscreenElement) {
|
||||||
|
document.exitFullscreen();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style module>
|
<style module>
|
||||||
|
|||||||
Reference in new issue
Block a user