AnythingSlider playground

Add, remove, adjust any or all options so you can see how it works.

by Mottie

HTML

<link rel="stylesheet" href="http://css-tricks.github.com/AnythingSlider/css/anythingslider.css">
<script src="http://css-tricks.github.com/AnythingSlider/js/jquery.anythingslider.js"></script>
<script src="http://css-tricks.github.com/AnythingSlider/js/jquery.easing.1.2.js"></script>
<script src="http://css-tricks.github.com/AnythingSlider/js/swfobject.js"></script>
<link rel="stylesheet" href="http://vjs.zencdn.net/3.2/video-js.css">
<script src="http://vjs.zencdn.net/3.2/video.js"></script>
<ul id="slider">
    <li>
        <video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="320" height="240" data-setup="{}">
            <source src="http://css-tricks.github.io/AnythingSlider/demos/video/movie.ogg" type="video/ogg"/>
            <source src="http://css-tricks.github.io/AnythingSlider/demos/video/movie.mp4" type="video/mp4"/>
            <source src="http://css-tricks.github.io/AnythingSlider/demos/video/movie.webm" type="video/webm"/>
            Your browser does not support the video tag. But you could include an iframe/embeded video here.
        </video>
    </li>
    <li>
        <img src="http://placehold.it/300x200" alt="" />
    </li>
    <li>
        <img src="http://placebear.com/300/200" alt="" />
    </li>
    <li>
        <img src="http://lorempixel.com/300/200" alt="" />
    </li>
    <li>
        <img src="http://placedog.com/300/200" alt="" />
    </li>
</ul>

CSS

/*** Set Slider dimensions here! Version 1.7+ ***/

/* added #slider li to make panels the same size in case "resizeContents" is false */
 ul#slider, ul#slider li {
    width: 300px;
    height: 200px;
    list-style: none;
}

JavaScript

var myPlayer = {
    "example_video_1": _V_("example_video_1")
    // add more videos here
    // , "example_video_2": _V_("example_video_2")
};

// Set up AnythingSlider
$('#slider').anythingSlider({
    // pause all videos when changing slides
    onSlideInit: function (e, slider) {
        for (var vid in myPlayer) {
            myPlayer[vid].pause();
        }
    },
    // Only play a paused video when a slide comes into view
    onSlideComplete: function (slider) {
        // the video gets wrapped in a div with the same ID
        var video = slider.$currentPage.find('div.video-js'),
            vid = video.attr('id');
        // find video-js class name & check if paused
        if (video.length && myPlayer[vid] && myPlayer[vid].paused()) {
            myPlayer[vid].play();
        }
    },
    // return true if video is playing or false if not
    isVideoPlaying: function (slider) {
        var video = slider.$currentPage.find('div.video-js'),
            vid = video.attr('id');
        if (video.length && myPlayer[vid] && !myPlayer[vid].paused()) {
            return true;
        }
        return false;
    }
});