简体   繁体   English

Fancybox不起作用

[英]Fancybox won't work

Can't seem to get Fancybox to work - it just links to the 1st pic. 似乎无法让Fancybox工作 - 它只是链接到第一张照片。 I get the error: uncaught typeerror object # an object has no method 'fancybox'. 我得到错误:未捕获的typeerror对象#一个对象没有方法'fancybox'。

HTML HTML

<a class="fancybox" data-thumbnail="http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/imagecache/timeout_slideshow_player_thumbnail/P1010923.JPG" href="http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/imagecache/timeout_492x330/P1010923.JPG"><img alt="" src="http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/toclogo.jpg"></a>

<br />

<a class="fancybox" data-thumbnail="http://fancyapps.com/fancybox/demo/2_s.jpg" href="http://fancyapps.com/fancybox/demo/2_b.jpg"></a>​

Javascript 使用Javascript

<script type="text/javascript">
    $(document).ready(function() {
        $(".fancybox").attr('rel', 'gallery').fancybox({
            helpers: {
                thumbs: {
                    width: 40,
                    height: 40,
                    source: function(current) {
                        return $(current.element).data('thumbnail');
                    }
                }
            }
        });
    });
</script>

Header

<!-- Add jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<!-- Add fancyBox -->
<link rel="stylesheet" href="/fancybox/source/jquery.fancybox.css?v=2.1.3" type="text/css" media="screen" />
<script type="text/javascript" src="/fancybox/source/jquery.fancybox.pack.js?v=2.1.3"></script>

It does seem to be pulling in the external files according to the Source in Chrome's Developer Tools. 根据Chrome开发者工具中的Source,它似乎确实在拉入外部文件。

Thx 谢谢

Hmmm. 嗯。 It looks like jquery is loaded twice. 看起来jquery加载了两次。 Once with 一次

<!-- Add jQuery library -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

and the other (harder to find) 和另一个(更难找到)

http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/advagg_js/js_13ec2e29dba08b369ccfdde54d836ec0_8.js

It looks like you're using drupal and with a bit of googling, it sounds like it injects a version of jquery for you (jQuery JavaScript Library v1.3.2) 看起来你正在使用drupal并使用一些谷歌搜索,听起来它为你注入了一个jquery版本(jQuery JavaScript Library v1.3.2)

The reason that error is occuring is the conflict between the two libraries. 发生错误的原因是两个库之间的冲突。 Try following this update http://drupal.org/project/jquery_update 请尝试关注此更新http://drupal.org/project/jquery_update

You're pulling in the two versions of jQuery. 你正在使用两个版本的jQuery。

When you execute jQuery(".fancybox").jquery from the console, you get 1.3.2 . 当您从控制台执行jQuery(".fancybox").jquery ,您将获得1.3.2 Undoubtedly, this is not compatible with fancybox. 毫无疑问,这与fancybox不兼容。

jQuery 1.8.2 is loaded via the Google CDN with your explicit script tag request. jQuery 1.8.2通过Google CDN加载了您的显式script标记请求。

jQuery 1.3.2 is loaded as part of http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/advagg_js/js_13ec2e29dba08b369ccfdde54d836ec0_8.js , which comes from Drupal injecting this library for its own purposes. jQuery 1.3.2是作为http://staging.timeoutchicago.com/sites/timeoutchicago.com/files/advagg_js/js_13ec2e29dba08b369ccfdde54d836ec0_8.js一部分加载的,它来自Drupal为自己的目的注入此库。

For future reference, I was able to locate this file by using the Chrome Developer Tools, sorting by file size (largest first) and then looking at the JS files... found it pretty quickly after that. 为了将来参考,我能够使用Chrome开发者工具找到这个文件,按文件大小排序(最大的第一个),然后查看JS文件......之后很快发现它。

I was having this same problem and I resolved it by changing the double quotes in the line: 我遇到了同样的问题,我通过更改行中的双引号来解决它:

$(".fancybox").fancybox();

To single quotes: 单引号:

$('.fancybox').fancybox();

Sort of a 'gotcha' since the fancyBox site has double quotes. 由于fancyBox网站有双引号,因此排序为'gotcha'。

if anything does not work: 如果有什么不起作用:

 parent.window.document.getElementById("fancybox-wrap").style.display = 'none';

This hiding fancybox. 这个隐藏的fancybox。

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

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