How can I trigger a lightbox2 body on load. I need a popup when user enters a site.
Thanks in advance.
How can I trigger a lightbox2 body on load. 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>
我有一个简单的链接,其中包括 url 末尾的“/lightbox2”和“rel”属性。
<a id='popup' href="url/lightbox2" rel="lightframe"> </a>
和 js 是这样的:
<script type='text/javascript'>
$(function() {
$('#popup').trigger('click');
});
</script>
为了显示一次,或者一段时间我使用 jQuery.cookie :)
或者是这样的:
$(function(){
// Link to open
$("#link").click();
});
在打开fancybox 之前,您确实需要先初始化fancybox。
现场演示:http: //jsfiddle.net/Y554b/1/