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 100 101 102 103 104 105 106
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="TutorielsjQuery/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(function() {
var timer;
$('.slide').mousemove(function(e) {
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
if(x <= 50) {
$(this).children('.flecheGauche').show();
$(this).children('.flecheDroite').hide();
}
else if(x >= 200) {
$(this).children('.flecheDroite').show();
$(this).children('.flecheGauche').hide();
}
else {
$(this).children('.flecheGauche').hide();
$(this).children('.flecheDroite').hide();
}
});
$('.slide').click(function(e) {
var x = e.pageX - this.offsetLeft;
var y = e.pageY - this.offsetTop;
if(x <= 50) { //Si lutilisateur clique sur la flèche de gauche.
animerInverse();
}
else if(x >= 200) { //Si lutilisateur clique sur la flèche de droite.
animer();
}
});
$('.slide').mouseout(function() {
$(this).children('.flecheGauche').hide();
$(this).children('.flecheDroite').hide();
});
function animer() {
$('.slide').animate({'background-position': '+=250'}, 500, function() {
if($('.slide').css('background-position') == 1000) {
$('.slide').css('background-position', 0);
}
});
}
function animerInverse() {
$('.slide').animate({'background-position': '-=250'}, 500, function() {
if($('.slide').css('background-position') == 0) {
$('.slide').css('background-position', 750);
}
});
}
timer = setInterval(animer, 5000);
});
</script>
<style language="text/css">
.slide {
background-image: url('image.png');
height: 250px;
width: 250px;
position: relative;
}
.flecheGauche {
display: none;
position: absolute;
background-image: url('flecheGauche.png');
height: 250px;
width: 50px;
}
.flecheDroite {
display: none;
position: absolute;
background-image: url('flecheDroite.png');
right: 0px;
height: 250px;
width: 50px;
}
</style>
</head>
<body>
<div class="slide">
<div class="flecheGauche"></div>
<div class="flecheDroite"></div>
</div>
</body>
</html> |
Partager