Compare commits
No commits in common. "fc5bbabd9deec071ffc692caeb8ef89c4c68e327" and "11a58d8e60aaa1b6d7a8c29264d0d2a7afa2a0f1" have entirely different histories.
fc5bbabd9d
...
11a58d8e60
2 changed files with 35 additions and 40 deletions
|
@ -47,7 +47,6 @@ const videos = [
|
||||||
muted
|
muted
|
||||||
controls
|
controls
|
||||||
playsinline
|
playsinline
|
||||||
preload="metadata"
|
|
||||||
>
|
>
|
||||||
<source src={path} type="video/mp4"/>
|
<source src={path} type="video/mp4"/>
|
||||||
</video>
|
</video>
|
||||||
|
@ -61,36 +60,18 @@ 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() {
|
||||||
setActiveVideo(0);
|
videos[0].play();
|
||||||
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,
|
||||||
|
@ -103,7 +84,9 @@ const videos = [
|
||||||
const video = entry.target as HTMLVideoElement;
|
const video = entry.target as HTMLVideoElement;
|
||||||
if (!entry.isIntersecting) {
|
if (!entry.isIntersecting) {
|
||||||
video.pause();
|
video.pause();
|
||||||
} else if (video === currentVideo) {
|
video.removeAttribute("autoplay")
|
||||||
|
video.currentTime = 0;
|
||||||
|
} else {
|
||||||
video.play();
|
video.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -113,25 +96,36 @@ const 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 == currentVideo && video.duration !== 0 && video.currentTime === video.duration) nextVideo();
|
if (video.duration !== 0 && video.currentTime === video.duration) nextVideo();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let wasPaused = false;
|
const onVisibilityChange = () => {
|
||||||
document.addEventListener("visibilitychange", () => {
|
for(const video of videos){
|
||||||
if (currentVideo) {
|
|
||||||
if(document.hidden){
|
if(document.hidden){
|
||||||
wasPaused = currentVideo.paused;
|
video.pause();
|
||||||
currentVideo.pause();
|
} else {
|
||||||
} else if (!wasPaused) {
|
video.play();
|
||||||
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", () => offsetCarousel(-1));
|
document.getElementById("marquee-scroll-left")!.addEventListener("mousedown", prevVideo);
|
||||||
document.getElementById("marquee-scroll-right")!.addEventListener("mousedown", () => offsetCarousel(1));
|
document.getElementById("marquee-scroll-right")!.addEventListener("mousedown", nextVideo);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -24,8 +24,9 @@ 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.PanelWindow for bars
|
Quickshell has two main window types available,
|
||||||
and widgets, and @@Quickshell.FloatingWindow for standard desktop windows.
|
[PanelWindow](/docs/types/quickshell/panelwindow) for bars and widgets, and
|
||||||
|
[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