简体   繁体   English

Fancybox 2在本地主机上不起作用

[英]Fancybox 2 don't work on localhost

I am pretty new to jQuery and I have never been using fancybox before. 我对jQuery非常陌生,而且以前从未使用过fancybox。 I tried to install it, but it doesn't work. 我试图安装它,但是它不起作用。 I used several test scripts I found, but still nothing. 我使用了一些发现的测试脚本,但仍然没有。 Here is my code: In head I have following (Paths to all files are correct): 这是我的代码:首先,我有以下内容(所有文件的路径均正确):

<script type="text/javascript" src="http://localhost/scripts/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.6"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>
<script src="http://localhost/scripts/jquery-2.1.1.js" type="text/javascript"></script>

And in my test document: 在我的测试文档中:

<script type='text/javascript'>
$(document).ready(function() {

    /* This is basic - uses default settings */

    $("a#single_image").fancybox();

    /* Using custom settings */

    $("a#inline").fancybox({
        'hideOnContentClick': true
    });


});
</script>
<a id="single_image" title="" href=""><img src="http://localhost/images/something.png" alt="" /></a>

But when I click on the image, nothing happens. 但是,当我单击图像时,什么也没有发生。

You are declaring your jquery script last. 您最后要声明您的jquery脚本。 That include should be first, preceeded by any other script that uses jquery. 应该首先包含include,然后再使用jquery的任何其他脚本。 nothing to do if it's on localhost or not. 无论是否在本地主机上,都无需执行任何操作。

<script src="http://localhost/scripts/jquery-2.1.1.js" type="text/javascript"></script>
<script type="text/javascript" src="http://localhost/scripts/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-buttons.css?v=1.0.5" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-media.js?v=1.0.6"></script>
<link rel="stylesheet" href="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-thumbs.css?v=1.0.7" type="text/css" media="screen" />
<script type="text/javascript" src="http://localhost/scripts/fancybox/source/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>

I have been having the same issue when your jquery-2.1.1.js. 我在使用jquery-2.1.1.js时遇到了同样的问题。 Once I used fancybox's provided jquery-1.10.1.js it worked however I got curious and tried jquery-1.9.1.js and my document stopped rendering the results. 一旦我使用了fancybox提供的jquery-1.10.1.js,它就可以工作,但是我很好奇并尝试了jquery-1.9.1.js,我的文档停止了呈现结果。

I don't know if it helps or you figured it out already but I thought I would add what I found. 我不知道这是否有帮助,或者您已经知道了,但是我想我会补充发现的内容。

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

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