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>
<script src="http://css-tricks.github.com/AnythingSlider/js/jquery.anythingslider.fx.js"></script>
<script src="http://css-tricks.github.com/AnythingSlider/js/jquery.anythingslider.video.js"></script>
<div id="display">current hash = <span id="current-hash">...</span></div>

<ul id="slider">
    
    <li>
        <img src="http://placekitten.com/320/200" alt="" />
        <h6 id="meow">Meow</h6>
    </li>
    <li>
        <img src="http://placehold.it/320x200" alt="" />
        <h6 id="grey">Grey</h6>
    </li>
    <li>
        <img src="http://placebear.com/320/200" alt="" />
        <h6 id="rawr">Rawr</h6>
    </li>
    <li>
        <img src="http://dummyimage.com/320x200/000/fff.jpg" alt="" />
        <h6 id="bnw">BnW</h6>
    </li>
    <li>
        <img src="http://placedog.com/320/200" alt="" />
        <h6 id="woof">Woof</h6>
    </li> 
</ul>

<!-- Add stylesheets here -->
<link rel="stylesheet" href="http://proloser.github.com/AnythingSlider/css/theme-metallic.css">

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: 320px;
    height: 200px;
    list-style: none;
}

#display {
    text-align: center;
    margin-bottom: 10px;
}

JavaScript

var display = $('#current-hash');

$('#slider').anythingSlider({

    // Should links change the hashtag in the URL?
    hashTags: false,
    
    // Details at the top of the file on this use (advanced use)
    navigationFormatter: function(index, panel) {
        return panel.find('h6').text();
    },

    // Callback when the plugin finished initializing
    onInitialized: function(e, slider) {
        if (window.location.hash) {
            slider.gotoPage(window.location.hash);
        }
        slider.$items.find('h6').each(function(){
            // add some prefix to the id so setting the hash doesn't
            // make the page jump
            this.id = "tmp_" + this.id;
        });
    },
    
    // Callback when slide completes - no event variable!
    onSlideComplete: function(slider) {
        var hash = '#' + slider.$currentPage.find('h6')[0].id.replace(/tmp_/,'');
        // remove prefix so hash works on page load
        window.location.hash = hash;
        
        // demo only
        display.text(hash);
    }

});