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 92 93 94 95 96 97 98 99
| <!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>HideShow</title>
<style>
#contenu1 {
width: 300px;
height: 200px;
font-size: 200%;
background-color: yellow;
position: absolute;
left: 300px;
top: 100px;
}
#contenu2 {
width: 300px;
height: 200px;
font-size: 200%;
background-color: yellow;
position: absolute;
left: 300px;
top: 100px;
}
h2.btn {
width: 10em;
border: 5px double black;
background-color: lightgray;
text-align: center;
font-family: sans-serif;
cursor:pointer;
}
</style>
</head>
<body>
<div class="conteneur">
<h2 id="bouton1" class="btn">bouton 1</h2>
<h2 id="bouton2" class="btn">bouton 2</h2>
<p id="contenu1">
Contenu 1
</p>
<p id="contenu2">
Contenu 2
</p>
</div>
<script charset="utf-8" src="http://code.jquery.com/jquery-1.7.min.js"></script>
<script>
"use strict";
$(function(){
$("#contenu1, #contenu2").hide();
var boolFade = false; // booléen pour poser la condition "passe la main"
function function_fadeIn1(){
$("#contenu1").fadeIn(250, function(){ // show
$(this).fadeOut(250, function(){ // hide
if (boolFade){
function_fadeIn2(); // passe la main
}
});
});
}
function function_fadeIn2(){
$("#contenu2").fadeIn(250, function(){ // show
$(this).fadeOut(250, function(){ // hide
if (boolFade){
function_fadeIn1(); // passe la main
}
});
});
};
$("#bouton1").click(function(){
boolFade = true;
function_fadeIn1();
setTimeout(function(){ // stop dans 4s
boolFade = false;
}, 4000); // 4000 milliseconds = 4s
});
$("#bouton2").click(function(){
boolFade = true;
function_fadeIn2();
setTimeout(function(){
boolFade = false;
}, 4000);
});
});
</script>
</body>
</html> |
Partager