【问题标题】:load div with images only when loaded仅在加载时加载带有图像的 div
【发布时间】:2012-12-14 16:00:23
【问题描述】:

我只想在加载图像时加载它们。

这不起作用,因为在加载图像之前删除了“隐藏”类:

$(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 示例吗? 这对我来说根本不起作用。

编辑 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."\" />";

我怎样才能让它与它一起工作?

【问题讨论】:

  • 你的意思是我只想显示图片只有在加载后才显示
  • 是的,布拉姆,我只想在加载时显示图像
  • 新编辑,适用于某些有效和无效的内容。

标签: jquery image load


【解决方案1】:

它能解决你的问题吗?

$('#images').load(function(){
    $(this).removeClass('hidden');
});

【讨论】:

    【解决方案2】:

    $('img').load() 不可靠,不能跨浏览器工作。 我会使用类似 waitForImages 的东西:https://github.com/alexanderdickson/waitForImages

    【讨论】:

    • 我想先在我的 div #id nowplaying 中加载 nowplaying.php。
    • 然后我想查看 div #id 中的图像 div #id 中的图像现在正在播放,只有在加载时。
    • 我最近在一个站点上使用了 waitForImages,该站点的所有数据都 ajaxed 并且主要基于图像,并且效果非常好。你试过什么?也许向我们展示您的代码?
    • waitForImages 应该做你所追求的,你需要更具体地说明你的问题
    • 我会使用 ajax 加载您的页面,然后在成功调用 waitforimages 然后在回调中删除隐藏的图像类,您可以在加载每个图像或所有图像都已加载时将其删除,取决于你想要什么
    【解决方案3】:

    也许你需要我的插件 - http://archive.plugins.jquery.com/project/BatchImagesLoad

    然后你可以在所有图片加载完成后进行操作。

    【讨论】:

      猜你喜欢
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-25
      • 1970-01-01
      • 2023-03-07
      • 2013-11-30
      相关资源
      最近更新 更多