mirror of
https://github.com/liyunze-coding/RythonDev.git
synced 2026-09-22 07:44:26 +00:00
added DOM interaction listener
This commit is contained in:
parent
8a0e5dc356
commit
bb79b3c590
1 changed files with 23 additions and 17 deletions
|
|
@ -4,6 +4,17 @@
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const videos = document.querySelectorAll<HTMLVideoElement>(".playable");
|
const videos = document.querySelectorAll<HTMLVideoElement>(".playable");
|
||||||
|
|
||||||
|
let userInteracted = false;
|
||||||
|
|
||||||
|
const handleUserInteraction = () => {
|
||||||
|
userInteracted = true;
|
||||||
|
document.removeEventListener("click", handleUserInteraction);
|
||||||
|
document.removeEventListener("keydown", handleUserInteraction);
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("click", handleUserInteraction);
|
||||||
|
document.addEventListener("keydown", handleUserInteraction);
|
||||||
|
|
||||||
videos.forEach((video) => {
|
videos.forEach((video) => {
|
||||||
// Ensure the video element supports play and pause methods
|
// Ensure the video element supports play and pause methods
|
||||||
if (
|
if (
|
||||||
|
|
@ -11,6 +22,11 @@
|
||||||
typeof video.pause === "function"
|
typeof video.pause === "function"
|
||||||
) {
|
) {
|
||||||
video.addEventListener("mouseenter", () => {
|
video.addEventListener("mouseenter", () => {
|
||||||
|
if (userInteracted) {
|
||||||
|
video.volume = 0.1;
|
||||||
|
} else {
|
||||||
|
video.muted = true;
|
||||||
|
}
|
||||||
video.play();
|
video.play();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -18,26 +34,16 @@
|
||||||
video.pause();
|
video.pause();
|
||||||
video.currentTime = 0;
|
video.currentTime = 0;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
videos.forEach((video) => {
|
// Check if the screen width is less than or equal to 768px (mobile screen size)
|
||||||
if (window.innerWidth < 1025) {
|
if (window.innerWidth <= 768) {
|
||||||
video.muted = true;
|
video.muted = true;
|
||||||
|
video.autoplay = true;
|
||||||
video.play();
|
video.play();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// On screen size change
|
|
||||||
window.addEventListener("resize", () => {
|
|
||||||
videos.forEach((video) => {
|
|
||||||
if (window.innerWidth < 1025) {
|
|
||||||
video.muted = true;
|
|
||||||
video.play();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="h-fit pt-20 [perspective:1000px] flex flex-col items-center">
|
<div class="h-fit pt-20 [perspective:1000px] flex flex-col items-center">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue