OK. Sale mais ça fonctionne parfaitement. Quelques modifications comme ajouter les images comme images de fond. C'est ici et j'espère que ça aide quelqu'un d'autre! Merci beaucoup à tous.
<script type="text/javascript">
$(function(){
var list = $("#list");
var li = list.children();
var lengthMinusOne = li.length - 1;
var index = 0;
var num = $("#list li").length;
var prevLi = $(li[0]).css("background-color", "gray");
$("#next").click(function(){
index++;
if (index > lengthMinusOne) index = 0;
prevLi.css("background-color","white");
prevLi = $(li[index]).css("background-color", "gray");
//Trigger a href click
$(prevLi).children('a').trigger('click');
//Display class in console
var myClass = $(prevLi).attr("class");
console.log(myClass);
});
$("#prev").click(function(){
index--;
if (index < 0) index = lengthMinusOne;
prevLi.css("background-color","white");
prevLi = $(li[index]).css("background-color", "gray");
//Trigger a href click
$(prevLi).children('a').trigger('click');
//Display class in consol
var myClass = $(prevLi).attr("class");
console.log(myClass);
});
//Loader
loader = $('#loader');
loader.hide();
var firstImg = $('<img />');
$(firstImg).attr('src',$('#list li a').attr('href'));
$('#image-holder').append(firstImg);
//get image and load into div
$('#list li a').click(function(event) {
//Add class to image within holder
oldImg = $('#image-holder img').addClass('old');
newImg = $('<img />');
$(newImg).attr('src',$(this).attr('href'));
//remove old image and show loader
$(oldImg).fadeOut().remove();
loader.show();
$(newImg).bind({
load: function() {
//console.log("Image loaded");
//Hide loader before fading in image
loader.hide();
$('#image-holder').append(newImg).hide().fadeIn(1300);
},
error: function() {
//console.log("Error thrown, image didn't load, probably a 404.");
}
});
event.preventDefault();
});
})
</script>
Vous ne chargez pas vraiment d'images via ajax. Chaque image fera sa propre demande pour l'image via l'attribut src. Si vous changez l'image src via JavaScript, elle chargera la nouvelle image. DutrowLLC est sur la bonne voie. – Gregg