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
| $(function() {
var
people = [],
jObjModal = $( '#fenetre_modale' );
$.getJSON( './js/exemple.json', function( data ){
people = data.Animaux;
$.each( people, function( i, f ) {
$( '<li>' + f.libelle + ' ' + '<img src="img/' + f.image + '"/></li>').appendTo( '.nav-list' );
});
});
// code dynamique, on() avec deux sélecteurs. Voir ma FAQ, lien dans la signature
$( ".nav-list" ).on( "click", "li", function( evt ){
var lien = $( evt.target ).attr( "src" ).slice( 4 ); // on doit enlever les caratères 0 à 4 : 'img/'
$.each( people, function( i, item ) {
if ( lien === item.image ) {
jObjModal
.html( '<h3>' + item.libelle + '</h3><p>' + item.texte + '</p>' )
.css({
"color" : "white",
"padding" : "0.6em",
"overflow" : "auto"
})
.fadeIn( 800 ); // 0.8s
setTimeout( function( ){
jObjModal.fadeOut( 800 ); // 0.8s
}, 10000 ); // 10s
return false; // exit each
}
});
});
}); |
Partager