nathansearles / slidesjs

SlidesJS is obsolete and no longer maintained.
https://nathansearles.github.io/slidesjs/
1.72k stars 356 forks source link

Video on a slidejs #524

Open johnlouie04 opened 11 years ago

johnlouie04 commented 11 years ago

Is there a possible way to play a video on the slide when the slider is on play state

gerbenvandijk commented 11 years ago

Hi @johnlouie04, as far as I can see it is not possible with the current build of slidesjs (3).

I' did a similar thing before though with an older version of slidesjs (2.0 beta 1 at the time), I would advise to use 1.2.0 that's available on http://archive.slidesjs.com/.

Firstly, add a class (in this case "video") to the slides that contain a video.

The JS required for this:

// Initiate slidesjs
$("#slides").slides({

    // The navigateEnd callback is fired when a slide is finished sliding in    
    navigateEnd: function( current ){

        // check if the current slide has a video
        classname = $(".active div").closest("div").attr("class");

        if(classname == "video"){

            // and start the video
            Froogaloop(video).api('play'); // in this case I've used the froogaloop api from vimeo to start the video, but you could also use the youtube JS api to do something similar, or if you have hosted your own video, use your own code.

        }

    }                      
});

// The code below is only relevant for the Vimeo API, but it should give you a global idea
// Initiate the vimeo API (you could write a function to do this so that you can use it for slideshows with more than one video in it)
var video = document.getElementById('idofvideo'),
player = $f(video);

// Adding an event for the start and end of the video
player.addEvent('ready', function() {

    player.addEvent('finish', onFinish);
    player.addEvent('play', onPlay);

});

// When the video starts
function onPlay(video) {

    // Stop the slider
    $("#slides").slides("stop");

}   

// When the video is done playing
function onFinish(video) {

    // Start the slider again
    $("#slides").slides("play");

}       
johnlouie04 commented 11 years ago

@gport woah nice.. this is a big help for me.. And I hope they add this feature on the future update.. Thanks for the information...

gerbenvandijk commented 11 years ago

No problem :+1: