2016-07-19 5 views
0

8秒ごとに背景画像を変更するスクリプトを作成しました。クロムですべてうまく動作しますが、他のブラウザではうまく動作しません。 (Safari、Edge、IE 9-11、Mozillaでテスト済み) jQueryプリロードプラグインもありますが、実際には画像をプリロードしません。コンソールにエラーが表示されないので、なぜ動作しないのかわかりません。 コード:

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); 

それも、「アニメーション」クラスを追加していない、何もしません。ここで

あなたは、ウェブサイトを見ることができます:助けをhttp://www.testing.dw-erfolg.eu/

感謝を!

答えて

0

あなたは簡略化したCSSプロパティを使用していますが、これはすべてのブラウザで保証されているわけではありません。

$('header .background .img').css('backgroundImage', 'url('+bgpath+')'); 
+0

こんにちは、あなたの助けに感謝します:

bgpath = $('header .background .img').css('background').match(/"(.*)"/), 

代わりに、あなたはまた、ライン42を変更することを確認してください.css('backgroundImage')

を使用する必要があります。また、$ .preloadが動作しない理由を知っていますか? – Jeremy

+0

その行の前にエラーがあったため、ブラウザがその部分に到達しない可能性があります。変更を加えて、再度確認してください。 – Dekel

+0

動作しませんでしたが、問題ではありません。私は別のものを使いました。とにかくありがとう! – Jeremy

関連する問題