自动打开fancyBox吗? [英] Open fancyBox automatically?

查看:85
本文介绍了自动打开fancyBox吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使fancyBox jQuery插件在网站首页加载后自动打开.我是Java和jQuery的新手,需要一些指针.

I'm currently working on trying to get the fancyBox jQuery plugin to open up automatically as soon as the front page of my site loads. I'm very new to Javascript and jQuery and need some pointers.

我的HEAD标记之间有以下代码.我只是想知道是否还有什么我可以插入到这里,以便在页面加载时打开fancyBox来打开.

I have the below code in between my HEAD tags. Just wondering if there's something else I can insert in here to I can get fancyBox to open up when the page loads.

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

我在fancyBox文档中找到了以下API方法,并且不确定这是否是我要找的东西.我似乎无法使其正常工作.

I found the following API method in the fancyBox documentation and wasn't sure if this is what I'm looking for or not. I couldn't seem to get it to work.

$.fancybox.open( [group], [options] )

有什么想法吗?

推荐答案

像这样设置它...

<a id="my-custom-trigger" class="gallery" href="http://moviebuzzers.com/wp-content/uploads/2012/08/paranorman-still.jpg">  
    <img src="http://moviebuzzers.com/wp-content/uploads/2012/08/paranorman-still.jpg" height="100"/>
</a>​

ID为"my-custom-trigger"的锚点是触发器->如果单击它,则会弹出fancybox. 因此,您需要在页面自动加载后点击"它.

Anchor with ID 'my-custom-trigger' is the trigger -> if you click it, fancybox pops out. So you need to 'click' it after page load automaticaly...

// Use document ready event, or window load,
// whichever one suits you the best...
$(window).load(function(){
    // Simulate click on trigger element
    $('#my-custom-trigger').trigger('click');
});

现在,您完成了!

这篇关于自动打开fancyBox吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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