Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

feat: scroll playing video into view

Christian Fei7ed4a35f923f
diff --git a/client/components/video-element.js b/client/components/video-element.js
index b2fd19a..579fb72 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -146,6 +146,7 @@ class VideoElement extends HTMLElement {
console.log('Video deleted')
this.video.downloaded = false
this.classList.remove('downloading')
+ this.querySelector('video') && this.unregisterVideoEvents(this.querySelector('video'))
this.render()
})
.catch((error) => console.error('Error deleting video:', error))
@@ -211,6 +212,7 @@ class VideoElement extends HTMLElement {
video.addEventListener('play', () => {
console.log('video event play')
this.classList.add('big')
+ setTimeout(this.scrollIntoViewWithOffset.bind(this, 150), document.querySelector('body > header').clientHeight)
this.pauseOtherVideos(video)
})
}
@@ -225,5 +227,11 @@ class VideoElement extends HTMLElement {
}
})
}
+
+ scrollIntoViewWithOffset (offset, behavior = 'smooth') {
+ const top = this.getBoundingClientRect().top - offset - document.body.getBoundingClientRect().top
+ window.scrollTo({ top, behavior })
+ }
}
+
customElements.define('video-element', VideoElement)
diff --git a/client/main.css b/client/main.css
index c06854e..7efe5f7 100644
--- a/client/main.css
+++ b/client/main.css
@@ -184,7 +184,7 @@ input[type="text"], input[type="url"], input[type="search"] {
video-element, video-element video {
- transition: width 0.2s ease-in;
+ transition: width 0.1s ease-in;
}
@media all and (min-width: 60em) {
.show-big-player video-element.big {