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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="Author" content="Daniel Hagnoul">
<title>Forum jQuery</title>
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Redressed&subset=latin&v2'>
<style>
/* Base */
html {font-size:62.5%; } /* Pour 62.5% 1rem =~ 10px */
div,p,h1,h2,h3,h4,h5,h6,ul,ol,dl,form,table,img {margin:0; padding:0; }
body {background-color:rgb(122, 79, 79); color:#000000; font-family:sans-serif; font-size:1.4rem; font-style:normal; font-weight:normal; line-height:normal; letter-spacing:normal; }
h1,h2,h3,h4,h5 {font-family:'Redressed', cursive; padding:0.6rem; }
p, div, td {word-wrap:break-word; }
pre, code {white-space:pre-wrap; word-wrap:break-word; }
img, input, textarea, select {max-width:100%; }
img {border:none; }
h1 {font-size:2.4rem; text-shadow: 0.4rem 0.4rem 0.4rem #bbbbbb; text-align:center; }
p {padding:0.6rem; }
ul {margin-left:2.4rem; }
.conteneur {width:95%; min-width:80rem; min-height:30rem; margin:1.2rem auto; background-color:#ffffff; color:#000000; border:0.1rem solid #666666; }
footer {margin-left:3.6rem; }
/* --- */
img.opac {width:20rem; height:20rem; }
</style>
</head>
<body>
<h1>Forum jQuery</h1>
<section class="conteneur">
<img id="opac0" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac1" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac2" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac3" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac4" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac5" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac6" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac7" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
<img id="opac8" class="opac" src="http://danielhagnoul.developpez.com/images/imageTest.png" />
</section>
<script charset="utf-8" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
"use strict";
$(function(){
/*
* Gestion du clic et du survol sur les éléments
* d'ID opacX. Remplace la méthode visible() et
* les onClick="visible('.$i.');javascript:return false;"
*/
var self = null, // l'élément cliqué
jObjOpac = $("[id^='opac']"); // l'objet jQuery incluant les éléments d'ID opacX
jObjOpac.click(function(){
// sauvegarde de l'élément cliqué
self = this;
jObjOpac.stop(true, true).fadeTo(200, 0.5);
$(self).fadeTo(200, 1);
return false;
}).hover( // gestion du survol si this n'est pas self
function(){ // mouseenter
if (this != self){
jObjOpac.stop(true, true).fadeTo(200, 0.5);
$(this).fadeTo(200, 1);
}
},
function(){ // mouseleave
if (this != self){
jObjOpac.stop(true, true).fadeTo(200, 0.5);
$(self).fadeTo(200, 1); // restaure self
}
}
);
});
$(window).load(function(){
/*
* Initialisation.
* Lorsque la page est chargée, on
* met l'opacité de tous les éléments
* à 0.5 puis on met le quatrième élément en évidence.
* eq() est base 0, donc 3 == quatrième élément
*/
$("[id^='opac']").eq(3).click();
});
</script>
</body>
</html> |
Partager