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

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

问题描述

我想在页面加载时启动Fancybox(例如 Fancybox的版本的模式或灯箱) .我可以将其绑定到隐藏的锚标签并通过JavaScript触发该锚标签的click事件,但我宁愿直接启动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当前不直接支持自动启动的方法.我能够解决的问题是创建一个隐藏的锚标记并触发它的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>

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

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