video handling, tweaks

This commit is contained in:
2024-02-19 17:12:43 +01:00
parent 73e4ea148c
commit 0cf9ddd7eb
3 changed files with 24 additions and 14 deletions
@@ -19,7 +19,7 @@ body {
transform: scale(var(--scale)); transform: scale(var(--scale));
transform-origin: 0 0; transform-origin: 0 0;
background-color: white; background-color: black;
margin: 0; margin: 0;
padding: 0; padding: 0;
@@ -133,6 +133,7 @@ button.slide-button.next {
position: relative; position: relative;
padding: 1rem 8rem; padding: 1rem 8rem;
height: calc(var(--height) / 4); height: calc(var(--height) / 4);
background-color: white;
overflow: auto; overflow: auto;
} }
+21 -10
View File
@@ -74,34 +74,45 @@ class Slider {
} }
onScroll(e) { onScroll(e) {
this.activeSlide = Math.round(e.target.scrollLeft / 800); let newSlide = Math.round(e.target.scrollLeft / 800);
if(this.activeSlide != newSlide) {
this.handleVideoPlayback(this.activeSlide, newSlide);
this.activeSlide = newSlide;
}
} }
next() { next() {
// stop old video
if (this.getType(this.activeSlide) == "video") {
this.slides[this.activeSlide].querySelector("video").pause();
}
// scroll to next slide // scroll to next slide
let targetSlide = this.activeSlide >= (this.data.length - 1) ? 0 : this.activeSlide + 1; let targetSlide = this.activeSlide >= (this.data.length - 1) ? 0 : this.activeSlide + 1;
this.element.scrollTo(targetSlide * 800, 0); this.element.scrollTo(targetSlide * 800, 0);
this.handleVideoPlayback(this.activeSlide, targetSlide);
this.start();
}
handleVideoPlayback(oldSlideIndex, newSlideIndex) {
// stop old video
if (this.getType(oldSlideIndex) == "video") {
this.slides[oldSlideIndex].querySelector("video").pause();
}
// start new video and timeout // start new video and timeout
if (this.getType(targetSlide) == "video") { if (this.getType(newSlideIndex) == "video") {
let video = this.slides[targetSlide].querySelector("video"); let video = this.slides[newSlideIndex].querySelector("video");
video.currentTime = 0 video.currentTime = 0
video.play(); video.play();
} }
this.start();
} }
previous() { previous() {
let targetSlide = this.activeSlide <= 0 ? (this.data.length - 1) : this.activeSlide - 1 let targetSlide = this.activeSlide <= 0 ? (this.data.length - 1) : this.activeSlide - 1
this.element.scrollTo(targetSlide * 800, 0); this.element.scrollTo(targetSlide * 800, 0);
this.handleVideoPlayback(this.activeSlide, targetSlide);
this.start(); this.start();
} }
@@ -1,8 +1,6 @@
var slides = [ var slides = [
{ {
image: "Hello World.mp4", image: "Hello World.mp4",
title: "",
description: ""
}, },
{ {
image: "placeholder-16x9.png", image: "placeholder-16x9.png",
@@ -17,6 +15,6 @@ var slides = [
{ {
image: "placeholder-16x9.png", image: "placeholder-16x9.png",
title: "Documentation", title: "Documentation",
description: `You can find manuals and information at [tooloop-os.org](https://tooloop-os.org).` description: `You can find manuals and information at **tooloop-os.org**.`
}, },
] ]