如何在页面加载时启动 jQuery Fancybox? [英] How to launch jQuery Fancybox on page load?

查看:16
本文介绍了如何在页面加载时启动 jQuery Fancybox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在页面加载时启动 Fancybox(例如 Fancybox 的 版本的模态框或灯箱).我可以将它绑定到隐藏的锚标记并通过 JavaScript 触发该锚标记的点击事件,但我宁愿直接启动 Fancybox 并避免额外的锚标记.

I would like to launch a Fancybox (e.g. Fancybox's version of a modal or light box) on page load. I could bind it to a hidden anchor tag and fire the click event of that anchor tag via JavaScript, but I would rather just launch the Fancybox directly and avoid the extra anchor tag.

推荐答案

Fancybox 目前不直接支持自动启动的方式.我能够开始工作的工作是创建一个隐藏的锚标记并触发它的点击事件.确保在包含 jQuery 和 Fancybox JS 文件之后包含触发点击事件的调用.我使用的代码如下:

Fancybox currently does not directly support a way to automatically launch. The work around I was able to get working is creating a hidden anchor tag and triggering it's click event. Make sure your call to trigger the click event is included after the jQuery and Fancybox JS files are included. The code I used is as follows:

此示例脚本直接嵌入在 HTML 中,但也可以包含在 JS 文件中.

This sample script is embedded directly in the HTML, but it could also be included in a JS file.

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

这篇关于如何在页面加载时启动 jQuery Fancybox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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