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
| <!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title> interval</title>>
<style>
#slideshow {
margin: 50px auto;
position: relative;
width: 313px;
height: 470px;
padding: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
}
#slideshow>div {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
bottom: 10px;
display: none;
}
#slideshow>div:first-child {
display: block;
}
</style>
</head>
<body>
<div id="slideshow">
<div>
<img src="textile/01.jpg">
</div>
<div>
<img src="textile/02.jpg">
</div>
<div>
<img src="textile/03.jpg">
</div>
<div>
<img src="textile/04.jpg">
</div>
<div>
<img src="textile/05.jpg">
</div>
</div>
<button id="bt_start" >start</button>
<button id="bt_stop" >stop</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
ref_interval = 0;
$('#bt_stop').prop("disabled",true);
function SlidIN() {
$('#slideshow > div:first')
.fadeOut(1000)
.next()
.fadeIn(1000)
.end()
.appendTo('#slideshow');
}
$('#bt_start').on('click', function() {
console.log('start');
ref_interval = setInterval( SlidIN , 3000);
$(this).prop("disabled",true);
$('#bt_stop').prop("disabled",false);
});
$('#bt_stop').on('click', function() {
console.log('stop');
clearInterval(ref_interval);
$(this).prop("disabled",true);
$('#bt_start').prop("disabled",false);
});
}); /// jQuery(document).ready
</script>
</body>
</html> |
Partager