Bonjour
Voici de nouveau le code indexé
(function(){
/*
Animation des images
_this.image.style.width = "100%"; -> images en responsive
*/
var animator_picture = function(nom, chemin, extension){
this.chemin = chemin;
this.extension = (extension !== undefined) ? extension : "png";
this.nom = nom;
this.image = undefined;
this.preload = function(callback){
var _this = this;
var imageChargee = new Image()
imageChargee.onload = function() {
_this.image.style.width = "100%";
if(callback && typeof(callback) === "function") callback(_this);
}
imageChargee.src = this.chemin + this.nom + "." + this.extension
this.image = imageChargee
}
}
/*
Animation du son
*/
var animator_sound = function(nom, chemin, extension, startAt){
this.chemin = chemin;
this.extension = (extension !== undefined) ? extension : "mp3";
this.nom = nom;
this.sound = undefined;
this.startAt = (startAt !== undefined) ? startAt : 0;
this.preload = function(callback){
var _this = this;
var soundCharge = new Audio()
soundCharge.onloadeddata = function() {
if(callback && typeof(callback) === "function") callback(_this);
};
soundCharge.src = this.chemin + this.nom + "." + this.extension
this.sound = soundCharge
}
}
/*
Chargement des images et du son coté client
*/
var animator = function(){
this.onStartPlaying = undefined;
this.onStopPlaying = undefined;
this.elementParent = undefined;
this.images = [];
this.sons = [];
this.timeOutId = undefined;
this.appendImages = function(tabImages){
this.images = this.images.concat(tabImages);
}
this.preloadAllImages = function(callback){
var compteur = 0;
var compteurFinal = this.images.length;
for(var i=0; i<this.images.length; i++){
if(this.images[i] instanceof animator_picture){
this.images[i].preload(function(img){
//console.log("image " + img.nom + " est chargée");
compteur++;
if(compteur === compteurFinal){
if(callback && typeof(callback) === "function") callback();
}
});
} else {
console.warn(this.images[i], i, "Not a animator_picture");
}
}
}
this.appendSounds = function(tabSounds){
this.sons = this.sons.concat(tabSounds);
}
this.preloadAllSounds = function(callback){
var compteur = 0;
var compteurFinal = this.sons.length;
for(var i=0; i<this.sons.length; i++){
if(this.sons[i] instanceof animator_sound){
this.sons[i].preload(function(son){
compteur++;
if(compteur === compteurFinal){
if(callback && typeof(callback) === "function") callback();
}
});
} else {
console.warn(this.sons[i], i, "Not a animator_sound");
}
}
}
this.preload = function(callback){
var imagesTelechargees = (this.images.length == 0) ? true : false;
var sonsTelecharges = (this.sons.length == 0) ? true : false;
var _this = this;
var fin = function(){
if(imagesTelechargees && sonsTelecharges){
if(callback && typeof(callback) === "function") callback();
}
}
if(!imagesTelechargees){
this.preloadAllImages(function(){
imagesTelechargees = true;
fin()
});
}
if(!sonsTelecharges){
this.preloadAllSounds(function(){
sonsTelecharges = true;
fin()
});
}
}
/*
Lance l'animation
- fps : number : description Frame per seconds
Prend en compte le nombre d'image à ne pas dépasser
Animation s'arrete des que toutes les images ont défilé
15 images par seconde
Son se déclenche à la 15 eme image
S'arrete automatiquement à la fin de toutes les images, ne se relance pas
*/
this.play = function(fps){
if(fps == undefined) fps = 15;
var compteur = 0;
var affichageSon = 0;
var _this = this
console.log('this.play')
if(this.onStartPlaying && typeof(this.onStartPlaying) == "function") this.onStartPlaying(this);
this.timeOutId = window.setInterval(function(){
if(compteur < _this.images.length){
//animation en cours
var image = _this.images[compteur];
_this.elementParent.innerHTML = '';
_this.elementParent.appendChild(image.image)
if(_this.sons.length > 0) {
if(compteur == _this.sons[0].startAt){
//console.log('debut du son', compteur)
_this.sons[0].sound.play()
}
}
compteur++
} else {
//animation finie
//console.log('animation finie')
if(_this.onStopPlaying && typeof(_this.onStopPlaying) == "function") _this.onStopPlaying(this);
clearInterval(_this.timeOutId)
}
}, 1000/fps)
}
}
/*
Génère sons et images
Images avec un début et une fin, une chaine de 4 caractères
Son avec un début
*/
var imgAnimator = {
create : function(elementParent, liste_images, son){
var _animation = new animator();
_animation.elementParent = elementParent;
_animation.appendImages(liste_images);
_animation.appendSounds(son);
return _animation;
},
generateListImages : function(repertoire, prefix_image, extension, start, end, formatageNbCharacter){
if(typeof(repertoire) !== "string") throw new Error("repertoire is not a string");
if(typeof(start) !== "number") throw new Error("Start is not a number");
if(typeof(end) !== "number") throw new Error("End is not a number");
var liste_images = [];
for(var i=start; i<=end; i++){
var _i = i;
if(formatageNbCharacter !== undefined){
var _i = i.toString();
if(_i.length < formatageNbCharacter){
for(var k=_i.length; k<formatageNbCharacter; k++){ _i = "0" + _i; }
}
}
var nom = prefix_image + _i;
var img = new animator_picture(nom, repertoire, extension);
liste_images.push(img);
}
return liste_images;
},
generateSound : function(repertoire, nom, extension, startAt){
if(typeof(repertoire) !== "string") throw new Error("repertoire is not a string");
var son = new animator_sound(nom, repertoire, extension, startAt);
return son;
}
};
// Objet principal dans le modèle
window.imgAnimator = imgAnimator;
})()
Alors mon problème est présent sur toutes les versions internet explorer. Légèrement sur firefox également.
Les images représentent un personnage qui arrive sur le site, et a chaque changement d'images le personnage donne l'impression de clignoter.
Pour info apres plusieurs essaies le personnage ne clignote plus sur ie (le problème est de nouveau présent lors de la suppression de l'historique de navigation)
Merci par avance