Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Simple Lightbox Perfect

Lightbox video intro to website

I just completed this lesson and now may have some use for it. I think? A client wants a short video intro when their site is visited. I already have the video. I know that the light box can be displayed on the event of a page loading. Is there a way to make the light box disappear automatically when the video finishes? Can you even put a video in a light box without linking to something like you tube, vimeo, etc? All the tutorials I can find show this method. Any help is appreciated. Thanks.

6 Answers

Jeremy Germenis
Jeremy Germenis
29,854 Points

You can use html5 video tags to display a non streaming service video you are hosting. You will just need the video in a few different formats for each browser.

You could then call a media event with something like

var video = ('#myVideo');
video.onended = function() {
      //CALL --> CLOSE LIGHTBOX
}

A link to html5 media events: http://www.w3.org/TR/html5/embedded-content-0.html#mediaevents

Thanks for the reply Jeremy. I will give that a try.

You may already be aware:

If the video file is already hosted somewhere you can use dirply.com to convert the file to the different formats without using a desktop app. The MP4 and webm formats are both necessary because each browser (desktop and mobile) supports one or the other.

Thanks Paul. That will come in handy as well.

Greg,

Typo - It should be dirpy.com.

For anyone else that may want to do this who happens to stumble across this post. I tried the .onended() function that Jeremy above mentioned. I could not get it to work for whatever reason. Maybe I was missing something. But, I found this bind function and it did work very easily. #myVideo is the id on the actual <video> html tag, #mask is my darkened background, .window contains the video.
The video now disappears when the video ends. Thanks again to those who helped in this post.

$('#myVideo').bind("ended", function(){
$('#mask').remove(); $('.window').remove(); });