Skip to content

Commit

Permalink
[Site] Play video only when visible (#423)
Browse files Browse the repository at this point in the history
This PR fixes some small css issues on the landing page and also adds
feature to only play the video when it's visible to users.
  • Loading branch information
Neet-Nestor authored May 25, 2024
1 parent e55d1eb commit d484637
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 23 additions & 0 deletions site/_includes/hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ <h1>WebLLM: High-Performance In-Browser LLM Serving Engine.</h1>
</section>

<script>
(function() {

function handlerIn(e) {
$(this).addClass("expanded");
}
Expand All @@ -47,4 +49,25 @@ <h1>WebLLM: High-Performance In-Browser LLM Serving Engine.</h1>

$(".chat-link").hover(handlerIn, handlerOut);
$(".github-link").hover(handlerIn, handlerOut);

var video = $("video")[0];
video.play().then((_) => {
let observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (
entry.intersectionRatio !== 1 &&
!video.paused
) {
video.pause();
} else if (video.paused) {
video.play();
}
});
},
{ threshold: 0.2 }
);
observer.observe(video);
});
})()
</script>
2 changes: 0 additions & 2 deletions site/assets/css/hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@
box-shadow: 0 0 0 1px rgba(0, 0, 0, .08);
margin-top: 96px;
width: 100%;
margin-left: -3rem;
max-width: 1024px;

aspect-ratio: 2292 / 1644;

video {
Expand Down

0 comments on commit d484637

Please sign in to comment.