.load() 不会为未缓存的图像触发 - jquery

.load() not firing for uncached images - jquery

本文关键字:图像 jquery 缓存 load      更新时间:2023-09-26

在 safari 和 opera 中,.load 的回调函数不会等待未缓存的图像完全加载。 使用缓存的图像,它工作得很好。

代码有点复杂,我会尝试简化...

所以,我的JS是这样的:

        $('#chatwindow_' + thread_id).load('/chat.php?thread_id=' + thread_id, function(){

            $('#chatwindow_' + thread_id).children('.chat_messagebox').load('/messages.php?sel=chat&latest_messages=10&thread_id=' + thread_id, function(){
//THIS IS BEING EXECUTED BEFORE THE IMAGES ARE FULLY LOADED, 
//BUT I EXPECT IT TO BE EXEC AFTER THE IMAGES ARE LOADED
                $(this).scrollTo('max',0);
                $('#chatwindow_' + thread_id).find('.messages_newcontent').focus();
        });

    });

消息.php?sel=chat:

<? include(gen_path("/messages_messagelist.php")); ?>

messages_messagelist.php:

while($x < $x_total){
load_attachments("message_".$message_row['id'], $max_width_of_att_field)
}

最后是函数中的重要片段:

return "<img src='/upload/attachments/".$attachments_row['id']."' width='160' class='download_file info_nextsibling' id='downloadfillabeobj_".$attachments_row['id']."'>"

就是这样 - 如果没有缓存这个最后的 ,它会在调用初始 .load 回调函数后完全加载 - 关于如何等待所有未缓存图像的任何想法?

在这里查看David DeSandro的imagesLoaded jQuery插件

从文档中:

"你不能在缓存的图像上做 .load()"