为什么 YUI 菜单等待我的页面图像加载?
编辑:这是 jQuery 1.3.1 中已确认的错误。 它在 jQuery 1.3.2 中得到修复。
我有一个 YUI 菜单控件,与 此示例 完全相同,带有子菜单顶端。
我尝试使用雅虎的代码来初始化菜单:
YAHOO.util.Event.onContentReady("mnuTopNav", function() {
var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
autosubmenudisplay: true,
hidedelay: 750,
lazyload: true
});
oMenuBar.render();
});
我发现页面上的图像需要一些时间才能加载。
我注意到标题会立即出现(通信/购物/娱乐),但指示有子项目的小箭头只有在加载所有图像后才会出现。
我觉得这很奇怪。 我什至尝试将代码切换到 JQuery,看看是否会在图像加载完成之前进行初始化(这就是我认为应该做的 $(function()
)。
$(function(){
var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
autosubmenudisplay: true,
hidedelay: 750,
lazyload: true
});
oMenuBar.render();
});
令我惊讶的是,我仍然有同样的问题。在加载整个页面之前,菜单不会初始化。
注意
:此问题仅在 Internet Explorer 中出现
。我解决这个问题吗?
Edit: This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery 1.3.2.
Edit: This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery 1.3.2.
I have a YUI menu control exactly like this sample with sub menus along the top.
I tried using Yahoo's code to initialize the menu :
YAHOO.util.Event.onContentReady("mnuTopNav", function() {
var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
autosubmenudisplay: true,
hidedelay: 750,
lazyload: true
});
oMenuBar.render();
});
I am seeing issues with pages that have images that take time to load.
I noticed that the headings would instantly appear (Communication/Shopping/Entertainment), but that the little arrows indicating there are sub-items wouldn't appear until all images are loaded.
I thought this very strange. I even tried switching out the code to JQuery to see if would initialize before the images are done loading (thats what $(function()
i thought was supposed to do).
$(function(){
var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
autosubmenudisplay: true,
hidedelay: 750,
lazyload: true
});
oMenuBar.render();
});
To my amazement I still had the same issue. The menu would not initialize until the whole page was loaded.
It is definitely the images that are being waited for.
Note: this problem is only in internet explorer. Firefox seems to raise this onContentReady event BEFORE the images are loaded.
Can i work around this problem?
Edit: This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery 1.3.2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过使用 YUI 的 onAvailable() 而不是 onContentReady() ? 来自 YUI 文档:
我的猜测是,浏览器需要在 nextSibling 属性起作用之前将图像加载到 DOM 上,因此 onContentReady() 正在等待。
Have you tried using YUI's onAvailable() instead of onContentReady()? From YUI's docs:
My guess is that the browser needs to load images onto the DOM before the nextSibling attribute works, so onContentReady() is waiting for that.
对于 jQuery 你应该这样做:
for jQuery you should do this:
雅虎的 onContentReady(...) 似乎由于某种原因等待图像加载,所以我已经停止使用它。
此外, $(function() { }); 的方式似乎存在 JQuery 错误。 请
参阅我的这篇文章,试图了解有关该问题的更多细节。
Yahoo's onContentReady(...) seems to wait for images to load for some reason so I've stopped using that.
In addition there appears to be a JQuery bug in how $(function() { }); works
See this post by me trying to get more specifics on the issue.