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>
<!-- required soundcloud api script -->
<script src="http://w.soundcloud.com/player/api.js"></script>
<ul id="slider">
<li><iframe width="100%" height="166" scrolling="no" frameborder="no" src="http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F5858290&show_artwork=true"></iframe></li>
<li><img src="http://placekitten.com/300/200" alt="" /></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
$(function() {
// store soundcloud audio player status
var scPlaying = [];
$('#slider').anythingSlider({
onInitialized: function(e, slider) {
slider.$items.filter(':not(.cloned)').each(function(i) {
var widget, aud = $(this).find('iframe[src*="soundcloud"]');
// false is the playing status
scPlaying[i] = false;
if (aud.length) {
aud.each(function() {
widget = SC.Widget(this);
widget.bind(SC.Widget.Events.READY, function() {
widget.bind(SC.Widget.Events.PLAY, function() {
scPlaying[i] = 'playing';
});
widget.bind(SC.Widget.Events.PAUSE, function() {
scPlaying[i] = 'paused';
});
widget.bind(SC.Widget.Events.FINISH, function() {
scPlaying[i] = 'finished';
});
});
});
}
});
},
// pause when changing slides
onSlideInit: function(e, slider) {
var audio = slider.$currentPage.find('iframe[src*="soundcloud"]');
if (audio.length) {
// pause all players when changing slides
audio.each(function() {
SC.Widget(this).pause();
});
}
},
// Only play a paused video when a slide comes into view
onSlideComplete: function(slider) {
var audio = slider.$currentPage.find('iframe[src*="soundcloud"]');
if (audio.length && scPlaying[slider.currentPage - 1] === 'paused') {
// using "audio[0]" will only start the first player in the slide
SC.Widget(audio[0]).play();
}
},
...