1

How can I trigger a lightbox2 body on load. I need a popup when user enters a site.

Thanks in advance.

4

3 回答 3

1
    <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>
于 2011-12-31T13:27:08.870 回答
0

我有一个简单的链接,其中包括 url 末尾的“/lightbox2”和“rel”属性。

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

和 js 是这样的:

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

为了显示一次,或者一段时间我使用 jQuery.cookie :)

于 2012-04-20T16:53:34.330 回答
0

或者是这样的:

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

在打开fancybox 之前,您确实需要先初始化fancybox。

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

于 2011-12-31T13:29:32.677 回答