Ich habe ein Skript gemacht, um Hintergrundbilder alle 8 Sekunden zu ändern. Alles funktioniert gut in Chrom, aber in anderen Browsern nicht. (Getestet auf Safari, Edge, IE 9 - 11 und Mozilla). Ich habe auch das jQuery Preload Plugin, aber es lädt die Bilder nicht vor. Die Konsole zeigt mir keine Fehler, deshalb weiß ich nicht, warum es nicht funktioniert. Code:
var c = 1,
nimg = $('header .background .img').attr('data-bg'),
bgpath = $('header .background .img').css('background').match(/"(.*)"/),
imgpath,
imgs = [],
startpath,
startpoint,
selector = 'header .background .content .text',
time = 8000;
if (path[1] == 'diwerf') {
startpath = '/'+path[1];
} else {
startpath = '/templates';
};
startpoint = bgpath[1].search(startpath);
bgpath = bgpath[1].slice(startpoint);
for (var g = 1; g <= nimg; g++) {
imgpath = bgpath.replace(/[0-9]/g, g);
imgs.push(imgpath);
};
$.preload(imgs);
function removeText() {
setTimeout(function() {
$(selector).fadeOut('slow', function() {
$(this).removeClass('animated').removeAttr('style');
});
}, time-600);
}
removeText();
setInterval(function() {
if (c == nimg) {
c = 0;
};
c++;
bgpath = bgpath.replace(/[0-9]/g, c);
$('header .background .img').css('background', 'url('+bgpath+') center center no-repeat');
setTimeout(function() {
$(selector+'-'+c).addClass('animated');
}, 600);
removeText();
}, time+100);
Es macht nichts, nicht einmal die 'animiert' Klasse hinzufügen.
Hier können Sie die Website: http://www.testing.dw-erfolg.eu/
Dank für die Hilfe!
Hallo, vielen Dank für Ihre Hilfe. Weißt du auch, warum das $ .preload nicht funktioniert? – Jeremy
Sie haben vor dieser Zeile einen Fehler gefunden, sodass der Browser möglicherweise nicht zu diesem Teil gelangt. Nehmen Sie die Änderungen vor und überprüfen Sie erneut. – Dekel
Es hat nicht funktioniert, ist aber egal. Ich habe etwas anderes benutzt. Danke trotzdem! – Jeremy