最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Auto load fancybox using .trigger('click') - Stack Overflow

programmeradmin4浏览0评论

I was just wondering if you could please help. I am trying to get the fancybox to load automatically once the page is rendered. However, I got this error message 't is undefined' at line 18 (/js/fancybox/ jquery.fancybox-1.3.3.pack.js). At the moment, I am using jquery version 1.4.2

<a href="#container" id="profile">Click me</a>

<div style="display:none">
<div id="container">Fancybox Content Here .... </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
      $('#profile').fancybox().trigger('click');

});

</script>

The funny thing is if I take the line below and run it in firebug console then it WORKS!. Not sure what did I do wrong here. Your helps would be grateful.

 $('#profile').fancybox().trigger('click');

Thanks

I was just wondering if you could please help. I am trying to get the fancybox to load automatically once the page is rendered. However, I got this error message 't is undefined' at line 18 (/js/fancybox/ jquery.fancybox-1.3.3.pack.js). At the moment, I am using jquery version 1.4.2

<a href="#container" id="profile">Click me</a>

<div style="display:none">
<div id="container">Fancybox Content Here .... </div>
</div>

<script type="text/javascript">
$(document).ready(function(){
      $('#profile').fancybox().trigger('click');

});

</script>

The funny thing is if I take the line below and run it in firebug console then it WORKS!. Not sure what did I do wrong here. Your helps would be grateful.

 $('#profile').fancybox().trigger('click');

Thanks

Share Improve this question edited Feb 17, 2011 at 13:46 jv42 8,5935 gold badges42 silver badges65 bronze badges asked Dec 14, 2010 at 13:19 Hung BuiHung Bui 311 gold badge1 silver badge2 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 13

I got the same problem. Testing with the unpacked version, i got "loading is undefined" in line 36 (fancybox 1.3.4). So I called "$.fancybox.init();" before triggering and it works correctly now.

Nope th reason is because the fancybox.js is included twice this is the file that has the core of fancy box

I've managed with the similar case in the way like this:

$(".some_wrapper").on('click', function(){
    var lnk = $(this).find("a").first();
    if (hr && ~cls.indexOf("fancybox-a")) {
        $.fancybox(lnk);
    }
});
发布评论

评论列表(0)

  1. 暂无评论