1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
$(document).ready(function() {
var inAnimation = false;
var z = $('#pictures img').length;
var image = new Image();
$('#pictures').append('<div id="loader"></div>'); //append the loader div, it overlaps all pictures
$('#pictures img').each(function(i, item) {
$(item).css('z-index', (i+1));
$(image).attr("src", $(item).attr("src")).load();
$("#affiche").append("<p>" + $(image).attr("src") + "</p>");
if ((i+1) == z) {
$('#loader').fadeOut('slow'); //remove the loader div
}
});
function swapFirstLast(isFirst) {
if(inAnimation) return false;
else inAnimation = true;
var processZindex, direction, newZindex, inDeCrease;
if(isFirst) { processZindex = z; direction = '-'; newZindex = 1; inDeCrease = 1; }
else { processZindex = 1; direction = '+'; newZindex = z; inDeCrease = -1; }
$('#pictures img').each(function(i, item) {
if ($(item).css('z-index') == processZindex) {
$(item).animate({'top': direction + $(item).height()}, 'slow', function() {
$(item).css('z-index', newZindex).animate({'top': '0'}, 'slow', function() {
inAnimation = false;
});
});
} else {
$(item).animate({'top': '0'}, 'slow', function() {
//make sure to wait swapping the z-index when image is above/under the gallery
//in/decrease the z-index by one
$(item).css('z-index', parseInt($(item).css('z-index')) + inDeCrease);
});
}
});
return false; //don't follow the clicked link
}
$('#next a').click(function() {
return swapFirstLast(true); //swap first image to last position
});
$('#prev a').click(function() {
return swapFirstLast(false); //swap last image to first position
});
}); |
Partager