scroll so that video is visible when expanded

This commit is contained in:
ccd0 2013-11-15 23:24:27 -08:00
parent 827bc5f0a1
commit 7de58faa21

View File

@ -65,6 +65,13 @@ function setupVideo(thumb, url) {
} }
} }
function scrollToVideo() {
var bottom = video.getBoundingClientRect().bottom;
if (bottom > window.innerHeight) {
window.scrollBy(0, bottom - window.innerHeight);
}
}
thumb.addEventListener("click", function(e) { thumb.addEventListener("click", function(e) {
if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
getVideo(); getVideo();
@ -84,6 +91,11 @@ function setupVideo(thumb, url) {
video.muted = setting("videomuted"); video.muted = setting("videomuted");
video.controls = true; video.controls = true;
if (video.readyState == 0) {
video.addEventListener("loadedmetadata", scrollToVideo, false);
} else {
scrollToVideo();
}
video.play(); video.play();
e.preventDefault(); e.preventDefault();
} }