0

画像が読み込まれたときにのみ画像を読み込みたい。

画像が読み込まれる前にクラス「hidden」が削除されるため、これは機能しません。

$(function(){
$('#nowplaying').load('nowplaying.php', function() {
    $('#images').removeClass('hidden');
}
)});

どうすればよいですか?

編集:ここに私のコードがあります:

index.php には次のものがあります。

<script type="text/javascript">
$(function(){
$('#nowplaying').load('nowplaying.php');
});
var auto_refresh = setInterval(
function ()
{
$('#nowplaying').load('nowplaying.php').fadeIn("slow");
}, 10000); // refresh every 10000 milliseconds
</script>

nowplaying.php には、次の div があります。

echo "<div id="images">;
foreach ($jpg_files as $file) {
if (file_exists($cover_path."\\\\".$file) && $file!="f.jpg") {
$file = urlencode($file);
echo "<a href=\"getimage.php?img=".$file."\" target=\"_blank\">
<img src=\"getimage.php?img=".$file."&p=".$cover_path."\" /></a>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
}
echo "</div>;

div id #images の画像がロードされたときにのみ表示したい (ブラウザで画像が作成されているのをユーザーに見せたくない)。

どうやってするの?

誰かが waitForImages の簡単な例を送ることができますか? 私にはまったくうまくいきません。

EDIT 12-12-15:これは機能しています:

<img style="display:none;" src="big3.jpg">
<script type="text/javascript">
$('img').load(function(){
    $(this).css({'display':'block'})
});
</script>

しかし、これは機能していません。なぜですか?:

<div style="display:none;">
    <img src="big3.jpg">
</div>
<script type="text/javascript">
$('div').load(function(){
    $(this).css({'display':'block'})
});
</script>

理由はまだわかりません。しかし、これは img に通常の src がある場合に機能します: div の下:

<script type="text/javascript">
$(document).ready(function(){
$("div.images").hide();
$("div.images").find("img").load(function(){
$(this).closest("div.images").show();
});
});
</script>

今ここに私の大きな問題があります:私の画像srcはスクリプトを呼び出しています:

<img src=\"getimage.php?img=".$file."\" />";

どうすればこれを機能させることができますか?

4

3 に答える 3

1

$('img').load()信頼性が低く、クロスブラウザで動作しません。私はwaitForImagesのようなものを使用します: https://github.com/alexanderdickson/waitForImages

于 2012-12-14T16:33:19.597 に答える
1

それはあなたの問題を解決しますか?

$('#images').load(function(){
    $(this).removeClass('hidden');
});
于 2012-12-14T16:04:24.967 に答える
0

私のプラグインが必要かもしれません - http://archive.plugins.jquery.com/project/BatchImagesLoad

その後、すべての画像が読み込まれた後に操作を実行できます。

于 2012-12-14T16:04:38.680 に答える