简体   繁体   English

Lightbox2页面加载触发器

[英]Lightbox2 pageload trigger

How can I trigger a lightbox2 body on load. 如何在加载时触发lightbox2主体。 I need a popup when user enters a site. 用户进入网站时,我需要一个弹出窗口。

Thanks in advance. 提前致谢。

    <script type="text/javascript">
        // Automagically load Lightbox on Page Load - by Bramus! (http://www.bram.us/)
        // Code modded from http://www.huddletogether.com/forum/comments.php?DiscussionID=1269&page=1#Item_0
        function autoFireLightbox() {
            //Check if location.hash matches a lightbox-anchor. If so, trigger popup of image.
            setTimeout(function() {
                if(document.location.hash && $(document.location.hash.substr(1)).rel.indexOf('lightbox')!=-1) {
                    myLightbox.start($(document.location.hash.substr(1)));
                }},
                250
            );
        }
        Event.observe(window, 'load', autoFireLightbox, false);
</script>

I have a simple link, that includes "/lightbox2" at the end of url, and "rel" attribute. 我有一个简单的链接,在URL的末尾包含“ / lightbox2”和“ rel”属性。

<a id='popup' href="url/lightbox2" rel="lightframe">&nbsp;</a>

And js something like this: 和js是这样的:

<script type='text/javascript'>
$(function() {
  $('#popup').trigger('click');
});
</script>

To show it once, or for a while I use jQuery.cookie :) 要显示一次,或使用jQuery.cookie一段时间:)

Or something like this: 或类似这样的东西:

$(function(){
     // Link to open
     $("#link").click();
});

You do need to initialize the fancybox first before you can open the fancybox. 您确实需要先初始化fancybox,然后才能打开fancybox。

Live demo: http://jsfiddle.net/Y554b/1/ 现场演示: http//jsfiddle.net/Y554b/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM