@JefReb :
Mais comme tu es bien curieux 
Une fois défini
- le temps de l'affichage de l'image (tps_par_image)
- le temps de l'effet du fade IN (tps_fade_in), on considère que cela sera le même temps pour l'extinction de l'image
- le nombre d'images à afficher (nbr_images)
on calcul aisément le temps total de l'animation (tps_animation)
tps_animation = tps_par_image * nbr_images
la fin de l'étape du fade IN, l'opacité passe à 1, est égale à
%_etape_1 = tps_fade_in / tps_animation
l'opacité reste à 1 jusqu'à
%_etape_2 = tps_par_image / tps_animation
la fin du fade OUT, l'opacité passe à 0 est égale à
%_etape_3 = (tps_par_image + tps_fade_in) / tps_animation
et l'opacité reste à 0 jusqu'à 100%.
Voilà rien de bien sorcier 
Fichier de calcul qui pourrait te servir
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 107 108 109 110 111 112 113 114 115 116
| <!DOCTYPE HTML>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name=viewport content="width=device-width, initial-scale=1.0">
<title>Calcul pour diapo fondu</title>
<meta name="Author" content="NoSmoking">
<style>
html, body {
margin: 0;
padding: 0;
font: 1em/1.25 Verdana,sans-serif;
background: #FFF;
}
#main {
max-width:60em;
margin: auto;
}
h1, h2, h3 {
margin: .25em 0;
color: #069;
}
fieldset {
max-width:40em;
margin: 1em;
padding: .5em;
}
legend {
color: #069;
font-weight: bold;
}
input {
font: inherit;
margin-left: .5em;
}
label {
display: block;
}
pre {
margin: 0;
font: 1em/1.25 "Courier New", monospace;
}
</style>
</head>
<body>
<div id="main">
<h1>Calcul pour diapo fondu</h1>
<fieldset>
<legend>Paramètres</legend>
<label>Temps par image</label>
<input type="number" id="tps_par_image" value="">
<label>Temps du fade in par image</label>
<input type="number" id="tps_fade_in" value="">
<label>Nombre images</label>
<input type="number" id="nbr_images" value="">
<label>Temps total animation</label>
<input type="number" id="tps_animation" value="" readonly>
</fieldset>
<fieldset>
<legend>CSS</legend>
<pre id="css_animation"></pre>
</fieldset>
</div>
<script>
var oInputs = document.querySelectorAll('input[id]');
/**
* Attention toutes les incohérences ne sont pas traitées
**/
function majChamps() {
var _r = {};
var anim = [];
var tab = ' ';
var pour_cent;
var i;
var oResultat = document.querySelector('#css_animation');
// récup. des valeurs
for ( i = 0; i < oInputs.length; i += 1) {
_r[oInputs[i].id] = parseInt(oInputs[i].value, 10) || 0;
}
_r.tps_animation = _r.tps_par_image * _r.nbr_images;
// mise à jour champs
document.querySelector('#tps_animation').value = _r.tps_animation;
// plus d'une image nécessaire pour traiter
if (_r.tps_animation > _r.tps_par_image) {
// définition animation
anim.push('.diaporama {\n animation: nom-animation ' + _r.tps_animation + 's linear infinite 0s;\n}');
// définition délai sur image
for (i = 0; i < _r.nbr_images; i += 1) {
anim.push('.diaporama img:nth-child(' + (i + 1) + ') { animation-delay: ' + (i * _r.tps_par_image) + 's;}');
}
// définition @keyframes
anim.push('\n@keyframes nom-animation {');
// étape 0
anim.push(tab + '0% { opacity: 0;}');
// étape fade in
pour_cent = ((_r.tps_fade_in / _r.tps_animation) * 100).toFixed(2);
anim.push(tab + pour_cent + '% { opacity: 1;}');
// étape reste affichée
pour_cent = ((_r.tps_par_image / _r.tps_animation) * 100).toFixed(2);
anim.push(tab + pour_cent + '% { opacity: 1;}');
// étape fin fade out
pour_cent = ((_r.tps_par_image + _r.tps_fade_in) / _r.tps_animation * 100).toFixed(2);
anim.push(tab + pour_cent + '% { opacity: 0;}');
// reste non visible
anim.push(tab + '100% { opacity: 0;}\n}');
}
// affiche CSS
oResultat.textContent = anim.join('\n');
}
// action sur change
for (var i = 0; i < oInputs.length; i += 1) {
oInputs[i].onchange = majChamps;
}
</script>
</body>
</html> |
[EDIT] correction coquille dans génération code CSS, manquait un s à @keyframes
Partager