Skip to content

Instantly share code, notes, and snippets.

@codler
Created December 6, 2011 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codler/1436072 to your computer and use it in GitHub Desktop.
Save codler/1436072 to your computer and use it in GitHub Desktop.
<script>
var queue = 0;
var last_index = 0;
jQuery(function ($) {
$(document).on('click', '#splash .left a', function () {
show_splash(--last_index);
return false;
});
$(document).on('click', '#splash .right a', function () {
show_splash(++last_index);
return false;
});
splash_list = get_splash_list();
rotate();
});
function rotate() {
setTimeout(function () {
show_splash(++last_index);
rotate();
}, 5000);
}
function get_splash_list() {
var list = [];
$('.album:first img').each(function() {
list.push({
'bild_url' : $(this).attr('src'),
'title' : $(this).attr('alt')
});
});
return list;
}
function show_splash(index) {
if (queue > 0) return;
queue += 2;
if (index < 1) index = 1;
if (index > splash_list.length) index = 1;
last_index = index;
index--;
var old = $('#splash');
var clone = $('#splash').clone();
clone.css({
'position' : 'absolute',
'top' : '115px',
'opacity' : 0
});
clone.find('#splash-inner').css({
'background-image' : "url('" + splash_list[index].bild_url + "')"
});
clone.find('.text h1').text(splash_list[index].title);
clone.find('.star:first').text(++index);
clone.insertAfter(old);
old.animate({opacity:0}, {
complete : function () {
$(this).remove();
queue--;
}
});
clone.animate({opacity:1}, {
complete : function () {
$(this).css({
'position' : '',
'top' : ''
});
queue--;
}
})
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment