使用 .trigger('click') 自动加载 fancybox

发布于 2024-10-07 16:28:16 字数 623 浏览 0 评论 0原文

我只是想知道你是否可以帮忙。我正在尝试获取 fancybox 在页面呈现后自动加载。然而,我 在第 18 行(/js/fancybox/ jquery.fancybox-1.3.3.pack.js)。目前,我正在使用jquery 版本 1.4.2

<a href="#container" id="profile">Click me</a>

<div style="display:none">
<div id="container">Fancybox Content Here .... </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
      $('#profile').fancybox().trigger('click');

});

</script>

有趣的是,如果我使用下面的行并在 firebug 中运行它 控制台然后它就可以了!不知道我在这里做错了什么。你的帮助 将不胜感激。

 $('#profile').fancybox().trigger('click');

谢谢

I was just wondering if you could please help. I am trying to get the
fancybox to load automatically once the page is rendered. However, I
got this error message 't is undefined' at line 18 (/js/fancybox/
jquery.fancybox-1.3.3.pack.js). At the moment, I am using jquery
version 1.4.2

<a href="#container" id="profile">Click me</a>

<div style="display:none">
<div id="container">Fancybox Content Here .... </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
      $('#profile').fancybox().trigger('click');

});

</script>

The funny thing is if I take the line below and run it in firebug
console then it WORKS!. Not sure what did I do wrong here. Your helps
would be grateful.

 $('#profile').fancybox().trigger('click');

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

扭转时空 2024-10-14 16:28:16

我遇到了同样的问题。使用解压版本进行测试,我在第 36 行(fancybox 1.3.4)中得到“加载未定义”。所以我调用了“$.fancybox.init();”在触发之前并且现在可以正常工作。

I got the same problem. Testing with the unpacked version, i got "loading is undefined" in line 36 (fancybox 1.3.4). So I called "$.fancybox.init();" before triggering and it works correctly now.

醉生梦死 2024-10-14 16:28:16

不,原因是因为 fancybox.js 被包含两次,这是具有 fancy box 核心的文件

Nope th reason is because the fancybox.js is included twice this is the file that has the core of fancy box

小鸟爱天空丶 2024-10-14 16:28:16

我已经用这样的方式处理过类似的情况:

$(".some_wrapper").on('click', function(){
    var lnk = $(this).find("a").first();
    if (hr && ~cls.indexOf("fancybox-a")) {
        $.fancybox(lnk);
    }
});

I've managed with the similar case in the way like this:

$(".some_wrapper").on('click', function(){
    var lnk = $(this).find("a").first();
    if (hr && ~cls.indexOf("fancybox-a")) {
        $.fancybox(lnk);
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文