且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在页面加载时启动jQuery Fancybox?

更新时间:2023-10-31 20:01:10

Fancybox当前不直接支持自动启动的方法.我能够解决的问题是创建一个隐藏的锚标记并触发它的click事件.确保包含jQuery和Fancybox JS文件之后包含触发click事件的调用.我使用的代码如下:

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>