2016-08-26 2 views
1

https://github.com/alexanderdickson/waitForImagesのプラグインを使用して画像がいつ読み込まれているかを検出しています。以下はプラグインが機能しないのを待つ画像

私のコードです:

$('.marquee').waitForImages(function() { 
    console.log('All images have loaded.'); 
    setTimeout(startMarquee); 
}, function(loaded, count, success) { 
    console.log(loaded + ' of ' + count + 
    ' images has ' + (success ? 'loaded' : 'failed to load') + '.'); 
    $(this).addClass('loaded'); 
}); 

イメージが完全にロードされたとき、私は画像のマーキースクロールを開始します。

私の問題は、いくつかのイメージがまだロードが、ちょうどこのような小さな空の正方形のボックスを表示していなかった、次のとおりです。 enter image description here

のプラグインも、それはすでにロードを検討してください。どのようにそれを修正するための任意のアイデア?

小さな空の四角いボックスのみを表示するのは、画像が読み込まれたと考えられますか?

+0

壊れたプラグイン - プラグインの作成者に報告すると、投稿者にはいいかもしれません –

+0

私は空のボックス画像をアップロードしました – Coolguy

+1

ありがとうございました。誰もここに誰も見ていないことを知っている人は誰もいません –

答えて

0

あなた自身で作成してください。

<marquee id="marquee" style="visiblity:hidden"> 
    <img src="image1.jpg" onload="countMe(this,1)" onerror="countMe(this,0)"/> 
    <img src="image1.jpg" onload="countMe(this,1)" onerror="countMe(this,0)"/> 
    <img src="image1.jpg" onload="countMe(this,1)" onerror="countMe(this,0)"/> 
</marquee> 

<script> 
var imageCount = 0, nofImages=$("#marquee img"); 
function countMe(img,success) { 
    if (!success) $(img).hide(); 
    imageCount++; 
    if (imageCount == nofImages) $("#marquee").show(); 
} 
</script> 

あなたは画像にチャンスを与えると、あなたのマーキーコードあなたを実行する前にロードされたすべてのページ画像まで待つしたい場合は永久的なエラーがあなたが

<marquee id="marquee" style="visiblity:hidden"> 
    <img src="image1.jpg" onload="countMe(this)" onerror="reloadMe(this)"/> 
    <img src="image2.jpg" onload="countMe(this)" onerror="reloadMe(this)"/> 
    <img src="image3.jpg" onload="countMe(this)" onerror="reloadMe(this)"/> 
</marquee> 

<script> 
var imageCount = 0, nofImages=$("#marquee img"); 
function countMe(img) { 
    imageCount++; 
    if (imageCount == nofImages) $("#marquee").show(); 
} 
function reloadMe(img) { 
    var tries = img.getAttribute("tries")?parseInt(img.getAttribute("tries"),10):1; 
    if (tries) == 3) return; // stop it 
    tries++; 
    img.setAttribute("tries",tries); 
    img.src=img.src; 
} 
</script> 
+0

あなたの関数は、壊れた画像を隠すでしょう。私は本当にイメージがほしいのですか?ページをリロードしますか? – Coolguy

+0

エラーが発生した場合、画像を取得しない可能性があります。イメージが存在する場合、エラーが発生する理由を修正する必要があります – mplungjan

+0

このようなことはできません: Coolguy

関連する問題