为什么 YUI 菜单等待我的页面图像加载?

发布于 2024-07-13 06:08:40 字数 1183 浏览 5 评论 0原文

编辑:这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

贪了杯 2024-07-20 06:08:40

您是否尝试过使用 YUI 的 onAvailable() 而不是 onContentReady() ? 来自 YUI 文档

onContentReady 方法共享一个
与 onAvailable 的语法相同。 这
两者之间的实质性差异
方法是 onContentReady 等待
直到目标元素及其
DOM 中的 nextSibling 响应
getElementById。 这保证了
目标元素的内容将
已完全加载(除了任何
您稍后可能添加的动态内容
通过脚本)。 如果 onContentReady 永远不会
检测到 nextSibling,它会触发
window.load 事件。

我的猜测是,浏览器需要在 nextSibling 属性起作用之前将图像加载到 DOM 上,因此 onContentReady() 正在等待。

Have you tried using YUI's onAvailable() instead of onContentReady()? From YUI's docs:

The onContentReady method shares an
identical syntax with onAvailable. The
material difference between the two
methods is that onContentReady waits
until both the target element and its
nextSibling in the DOM respond to
getElementById. This guarantees that
the target element's contents will
have loaded fully (excepting any
dynamic content you might add later
via script). If onContentReady never
detects a nextSibling, it fires with
the window.load event.

My guess is that the browser needs to load images onto the DOM before the nextSibling attribute works, so onContentReady() is waiting for that.

扎心 2024-07-20 06:08:40

对于 jQuery 你应该这样做:

    $(document).ready(function(){


        var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
            autosubmenudisplay: true,
            hidedelay: 750,
            lazyload: true
        });

        oMenuBar.render();
   });

for jQuery you should do this:

    $(document).ready(function(){


        var oMenuBar = new YAHOO.widget.MenuBar("mnuTopNav", {
            autosubmenudisplay: true,
            hidedelay: 750,
            lazyload: true
        });

        oMenuBar.render();
   });
困倦 2024-07-20 06:08:40

雅虎的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文