diff options
| author | ccd0 <admin@containerchan.org> | 2013-11-15 23:24:27 -0800 |
|---|---|---|
| committer | ccd0 <admin@containerchan.org> | 2013-11-15 23:24:27 -0800 |
| commit | 7de58faa21d7071f91e3eea47452d150d7a7bfc6 (patch) | |
| tree | 546fa1630c71deaf739e83df515b53c4927904e5 | |
| parent | 827bc5f0a1b2ce1e7bd1ac844190338914ed38e4 (diff) | |
scroll so that video is visible when expanded
| -rw-r--r-- | expandvideo.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/expandvideo.js b/expandvideo.js index db7f3ecd..4e94a007 100644 --- a/expandvideo.js +++ b/expandvideo.js @@ -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) { if (setting("videoexpand") && !e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) { getVideo(); @@ -84,6 +91,11 @@ function setupVideo(thumb, url) { video.muted = setting("videomuted"); video.controls = true; + if (video.readyState == 0) { + video.addEventListener("loadedmetadata", scrollToVideo, false); + } else { + scrollToVideo(); + } video.play(); e.preventDefault(); } |
