How to display a lightbox after a video game is completed?

I have a YouTube video.

I want to show the lightbox when it stops playing. I need this to be done using javascript / jQuery or PHP. Ajax is also beautiful.

I was looking for a solution, but could not find what worked.

+5
source share
1 answer

If you can use youtube api then something like this should work:


<script type="text/javascript">
$(document).ready(function() {
var player;
    function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          height: '390',
          width: '640',
          videoId: 'YmHAAqOsBqA',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
    }
    function onPlayerReady(event) {
        event.target.playVideo();
    }
    function onPlayerStateChange(event) {        
        if(event.data === 0) {          
            //completed playing
            //open lightbox
            $('#yourElementId a').lightBox();
        }
    }
});
</script>

You mean something like this.

Hope this helps

+6
source

All Articles