jQuery在执行document.ready之前正在等待图像加载. [英] JQuery is waiting for images to load before executing document.ready

查看:105
本文介绍了jQuery在执行document.ready之前正在等待图像加载.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新: 至少有两个人确认了此错误.即使您没有阅读我的完整文章-如果您正在阅读本文并使用JQuery 1.3.1,那么如果您依赖要在DOM完成后执行的任何处理程序,请停止使用但在加载页面图像之前.

Update: This bug has been confirmed by at least two others. Even if you dont read my full post - if you're reading this and using JQuery 1.3.1 then stop using it if you're relying on any handlers that you want to execute when the DOM is complete but before the page's images have loaded.

Update2 :感谢 Tom (用户ID 20!)发布了链接到票证,在jQuery Bug跟踪器上.

Update2: Thanks to Tom (user id 20!) for posting the link to the ticket on the jQuery bug tracker.

Update3-2009/01/28 :该问题已正确解决(对于那些无法恢复到1.2.6的用户而言).对于当前使用1.3.1并需要立即修复的任何人,您可以阅读下面接受的答案以获取指导.谢谢约翰.

Update3 - 2009/01/28: The issue has been properly resolved (for those for whom reverting to 1.2.6 is not an option). For anyone currently using 1.3.1 and needing an immediate fix you can read the accepted answer below for direction. Thanks John.

我刚刚升级到JQuery 1.3.1,花了几个小时才意识到自己心爱的人

I just upgraded to JQuery 1.3.1, and it took me several hours to realize that my beloved

$(function( ) {  ... }

语法现在在执行功能主体之前正在等待整个页面加载(包括图像).尝试集成Yahoo的菜单时,我看到了奇怪的行为. (幸运的是,我在页面上加载了一些缓慢的图像,这使我意识到了这个问题)!

syntax was now waiting for the entire page to load (including images) before executing the function body. I was seeing strange behavior when trying to integrate Yahoo's menus. (Fortunately I had some slow loading images on my page which made me aware of the problem)!

我制作了一个测试文件,因为我发现发生了一些更复杂的事情,但是即使使用这个简单的文件,我仍然有相同的症状.

I made a test file becasue I figured something more complex was going on, but I still had the same symptoms even with this simple file.

<head>
   <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>   
   <script>
    $(function() {    
      alert("Ready"); 
    });
  </script>
</head>

<body>      
  <img src="<PATH_TO_DYNAMIC_IMAGE>_1.jpg" />
  <img src="<PATH_TO_DYNAMIC_IMAGE>_2.jpg" />
  <img src="<PATH_TO_DYNAMIC_IMAGE>_3.jpg" />
  <img src="<PATH_TO_DYNAMIC_IMAGE>_4.jpg" />       
</body>

JQuery的不同版本具有不同的结果:

Different versions of JQuery had different results:

  • 1.2.6版中发生的事情是立即显示警报框,然后我看到它后面的图像正在加载(预期和记录的行为).
  • 1.3.1版中发生的是图像全部加载,然后才显示警报框.

怎么回事!这是一个新功能(我无法想象为什么)还是一个错误?

Whats going on! Is this a new feature (I cant imagine why) or a bug?

重要提示:这似乎只是IE中的问题,而不是firefox

对不起,我没有一个动态图像文件可供公共访问,以使其他人更容易看到.如果您想对其进行测试,建议您使用从Google图片中随机选择的大图片文件,然后清除缓存.

推荐答案

这是由于jQuery错误# 2614 和# 3880 -IE 1.2中的就绪代码确实存在问题. 6和1.3中的问题-现在是1.3.1.中的另一组问题.

This was due to jQuery bugs #2614 and #3880 - there were definite problems with the ready code in IE in 1.2.6 and in 1.3 - and now a different set of problems in 1.3.1.

可以在这里找到更大的讨论:

A larger discussion can be found here:
http://groups.google.com/group/jquery-dev/browse_thread/thread/3abf45d3fd4d50fc

与问题相关的票证可以在这里找到(如果您发现与该修复程序有关的其他问题,请重新打开票证并将其发布到上面的jquery-dev线程中):
http://dev.jquery.com/ticket/3988

And the ticket related to the issue can be found here (if you find additional issues with the fix, please re-open the ticket and post to the above jquery-dev thread):
http://dev.jquery.com/ticket/3988

我刚刚在SVN版本 6170 中找到了针对此问题的修复程序.

I just landed a fix for this in SVN rev 6170.

我刚刚推了一个新的每晚,您可以使用它直到1.3.2最终版发布:
http://code.jquery.com /nightlies/jquery-2009-01-28.js

I just pushed up a new nightly that you can use until 1.3.2 final comes out:
http://code.jquery.com/nightlies/jquery-2009-01-28.js

抱歉,无法及时提供修复程序-本周旅行.

Sorry in the delay for getting a fix out - was traveling this week.

这篇关于jQuery在执行document.ready之前正在等待图像加载.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆