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
| <!DOCTYPE html>
<html lang="fr" dir="ltr">
<head>
<meta http-equiv="cache-control" content="public, max-age=60">
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0">
<meta name="author" content="Daniel Hagnoul">
<title>Test</title>
</head>
<body>
<label for="progressBar">Progression du chargement des courriels : </label>
<progress id="progressBar" value="0" max="100"></progress>
<input id="progressText" type="text" size="5" value="0 %">
<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script type="module">
let
allCourriel = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k" ],
allCourrielLength = allCourriel.length;
function* generator( ){
let
index = 0;
while ( index < allCourrielLength ){
yield [ index, allCourriel[ index++ ] ];
}
}
let
iterator = generator(),
obj = iterator.next();
function progression( ){
if ( ! obj.done ){ // tant que false
// debug, console, touche F12
console.log( obj.value );
// calcul et affichage du pourcentage
let
pourcent = 100 * ( ( obj.value[ 0 ] + 1 ) / allCourrielLength );
$( "#progressBar" ).val( pourcent );
$( "#progressText" ).val( pourcent.toFixed( 2 ) + " %" );
// il faut ralentir l'action pour voir la progression
setTimeout( function( ){
obj = iterator.next(); // obj suivant
progression(); // appel récursif
}, 500 ); // 0.5s
}
}
progression(); // action !
</script>
</body>
</html> |
Partager