0

如果哈希在 url 中可用,我正在尝试让 fancybox 触发,问题是我使用了不同的方法,其中一些是从 stackoverflow 中获取的,在 Firefox 的错误控制台中返回“c not available”。我尝试这个的网站可以在这里找到 http://rojava.se/om/#infor。非常感谢所有帮助

我尝试过的方法: 如何创建指向任何精美盒子的直接链接

    <script type="text/javascript">
var thisHash = window.location.hash;
$(document).ready(function() {
 if(window.location.hash) {
  $(thisHash).fancybox({
    padding: 0
    // more API options
  }).trigger('click');
 }
 $('.fancylink').fancybox({
    padding: 0
    // more API options
 });
}); // ready
</script>

第二种方法:Fancybox 不会在 $(elem).click() 上触发,但会在“真实”点击时触发?

jQuery('a[href="http://hallarna.se/wp-content/gallery/2013/spoksonatenloggaliten.jpg"]').trigger('mousedown').trigger('click');
4

1 回答 1

2

你必须做两件事:

1)。更改您的触发代码:

目前您正在使用此触发器:

var thisHash = window.location.hash;
if(window.location.hash) {
    $(thisHash).trigger('mousedown').trigger('click');      
}

但是您对自己说,您尝试了这篇文章的解决方案How to create a direct link to any fancybox box因此您的代码必须如下所示:

var thisHash = window.location.hash;
if(window.location.hash) {
    $(thisHash).fancybox().trigger('click');        
}

因为选择器#infor没有绑定到 fancybox (v1.3.4) 所以你需要bind在触发click.

2)。在 fancybox 初始化之后调用你的触发代码。

还是不行?这是一个吊装问题。您的触发代码当前位于<head>文档的部分中,但是页面底部正在调用fancybox.js文件,因此即使按照上面的建议更改代码也不会触发,因为尚未初始化 fancybox。

将您的代码放在fancybox 调用和初始化之后以及结束</body>标记之前,例如:

<script type='text/javascript' src='http://rojava.se/wp-content/plugins/easy-fancybox/fancybox/jquery.fancybox-1.3.5.pack.js?ver=1.5.5'></script>
<script type='text/javascript' src='http://rojava.se/wp-content/plugins/easy-fancybox/jquery.easing.pack.js?ver=1.3'></script>

<script type="text/javascript">
jQuery(document).on('ready post-load', easy_fancybox_handler );
jQuery.noConflict();
(function($) {
  $(function() {
    $('#footbuttoncontainer ').click(function() {
      container = $('#footcontentcontainer');
      if(container.height() > 20){
        $('#footcontentcontainer').animate({height:"0"}, 1000);
      } else {
        $('#footcontentcontainer').animate({height:"26vmin"}, 1000);
      }
    });
    var thisHash = window.location.hash;     
    if(window.location.hash) {
      $(thisHash).fancybox().trigger('click');
    }
  });
})(jQuery);
</script>
</body>

请注意,我在fancybox init 之后移动了您的完整代码块。

现在看到它与hash包含在 URL 中的一起工作:

http://www.picssel.com/playground/jquery/rojava.html#infor

于 2013-09-11T09:12:07.327 回答