Compare commits
2 commits
11a58d8e60
...
fc5bbabd9d
Author | SHA1 | Date | |
---|---|---|---|
fc5bbabd9d | |||
1bbf453ae7 |
2 changed files with 40 additions and 35 deletions
|
@ -47,6 +47,7 @@ const videos = [
|
||||||
muted
|
muted
|
||||||
controls
|
controls
|
||||||
playsinline
|
playsinline
|
||||||
|
preload="metadata"
|
||||||
>
|
>
|
||||||
<source src={path} type="video/mp4"/>
|
<source src={path} type="video/mp4"/>
|
||||||
</video>
|
</video>
|
||||||
|
@ -60,18 +61,36 @@ const videos = [
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// marquee
|
|
||||||
const videoCount = 5; // last array index
|
const videoCount = 5; // last array index
|
||||||
const marquee = document.getElementById("marquee-content")!;
|
const marquee = document.getElementById("marquee-content")!;
|
||||||
marquee.style.setProperty("--scroll", "0")
|
marquee.style.setProperty("--scroll", "0")
|
||||||
|
|
||||||
// autoplay
|
|
||||||
window.addEventListener("load", autoplayInit, false);
|
window.addEventListener("load", autoplayInit, false);
|
||||||
const videos = document.getElementsByClassName("marquee-item-content") as HTMLCollectionOf<HTMLVideoElement>;
|
const videos = document.getElementsByClassName("marquee-item-content") as HTMLCollectionOf<HTMLVideoElement>;
|
||||||
|
let currentVideoIndex = 0;
|
||||||
|
let currentVideo = null;
|
||||||
|
|
||||||
function autoplayInit() {
|
function autoplayInit() {
|
||||||
videos[0].play();
|
setActiveVideo(0);
|
||||||
};
|
currentVideo.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setActiveVideo(index: number) {
|
||||||
|
console.log("setActive", index);
|
||||||
|
currentVideo?.pause();
|
||||||
|
|
||||||
|
currentVideoIndex = index;
|
||||||
|
currentVideo = videos[currentVideoIndex];
|
||||||
|
currentVideo.currentTime = 0;
|
||||||
|
marquee.style.setProperty("--scroll", `-${currentVideoIndex*100}%`)
|
||||||
|
}
|
||||||
|
|
||||||
|
function offsetCarousel(offset: number) {
|
||||||
|
let nextIndex = currentVideoIndex + offset;
|
||||||
|
if (nextIndex < 0) nextIndex += videoCount;
|
||||||
|
nextIndex = nextIndex % videoCount;
|
||||||
|
setActiveVideo(nextIndex);
|
||||||
|
}
|
||||||
|
|
||||||
const intersectionOptions = {
|
const intersectionOptions = {
|
||||||
root: marquee,
|
root: marquee,
|
||||||
|
@ -84,48 +103,35 @@ const videos = [
|
||||||
const video = entry.target as HTMLVideoElement;
|
const video = entry.target as HTMLVideoElement;
|
||||||
if (!entry.isIntersecting) {
|
if (!entry.isIntersecting) {
|
||||||
video.pause();
|
video.pause();
|
||||||
video.removeAttribute("autoplay")
|
} else if (video === currentVideo) {
|
||||||
video.currentTime = 0;
|
|
||||||
} else {
|
|
||||||
video.play();
|
video.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},intersectionOptions);
|
}, intersectionOptions);
|
||||||
|
|
||||||
for (const video of videos) {
|
for (const video of videos) {
|
||||||
observer.observe(video);
|
observer.observe(video);
|
||||||
|
|
||||||
video.addEventListener("ended", () => {
|
video.addEventListener("ended", () => {
|
||||||
|
console.log("video ended", "duration", video.duration, "ctime", video.currentTime);
|
||||||
// The "ended" event might just mean its buffering.
|
// The "ended" event might just mean its buffering.
|
||||||
if (video.duration !== 0 && video.currentTime === video.duration) nextVideo();
|
if (video == currentVideo && video.duration !== 0 && video.currentTime === video.duration) nextVideo();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const onVisibilityChange = () => {
|
let wasPaused = false;
|
||||||
for(const video of videos){
|
document.addEventListener("visibilitychange", () => {
|
||||||
if(document.hidden){
|
if (currentVideo) {
|
||||||
video.pause();
|
if (document.hidden) {
|
||||||
} else {
|
wasPaused = currentVideo.paused;
|
||||||
video.play();
|
currentVideo.pause();
|
||||||
|
} else if (!wasPaused) {
|
||||||
|
currentVideo.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
||||||
|
|
||||||
function offsetCarousel(offset: number) {
|
|
||||||
const currentIndex = Number(marquee.getAttribute("data-media-index"));
|
|
||||||
let nextIndex = currentIndex + offset;
|
|
||||||
if (nextIndex < 0) nextIndex += videoCount;
|
|
||||||
nextIndex = nextIndex % videoCount;
|
|
||||||
|
|
||||||
marquee.setAttribute("data-media-index", `${nextIndex}`);
|
|
||||||
marquee.style.setProperty("--scroll", `-${nextIndex*100}%`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function prevVideo() { offsetCarousel(-1) }
|
|
||||||
function nextVideo() { offsetCarousel(1) }
|
|
||||||
|
|
||||||
// left-right buttons
|
// left-right buttons
|
||||||
document.getElementById("marquee-scroll-left")!.addEventListener("mousedown", prevVideo);
|
document.getElementById("marquee-scroll-left")!.addEventListener("mousedown", () => offsetCarousel(-1));
|
||||||
document.getElementById("marquee-scroll-right")!.addEventListener("mousedown", nextVideo);
|
document.getElementById("marquee-scroll-right")!.addEventListener("mousedown", () => offsetCarousel(1));
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -24,9 +24,8 @@ Configs at other paths, including raw qml files can be run with `--path` or `-p`
|
||||||
|
|
||||||
## Creating Windows
|
## Creating Windows
|
||||||
|
|
||||||
Quickshell has two main window types available,
|
Quickshell has two main window types available, @@Quickshell.PanelWindow for bars
|
||||||
[PanelWindow](/docs/types/quickshell/panelwindow) for bars and widgets, and
|
and widgets, and @@Quickshell.FloatingWindow for standard desktop windows.
|
||||||
[FloatingWindow](/docs/types/quickshell/floatingwindow) for standard desktop windows.
|
|
||||||
|
|
||||||
We'll start with an example:
|
We'll start with an example:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue