JQuery无法正常工作。 (功能)

时间:2015-12-02 17:41:52

标签: javascript jquery fancybox

所以当我把

$(document).ready(function() {
    $(".fancybox").fancybox();
});

位于此

的顶部
$(function() {  
    jQuery.scrollSpeed(1920, 800); 
});

$(document).ready(function(e) {
    $("#open-io").click(function (){
        //console.log("asdfasdf");
        $("#navi").addClass("expand");
    });

    $("#close-io").click(function (){
        //console.log("asdfasdf");
        $("#navi").removeClass("expand");
    });
});

不是全部工作。

但是,如果我将顶部的一个放在底部,那么就像这样

$(function() {  
    jQuery.scrollSpeed(1920, 800); 
});

$(document).ready(function(e) {
    $("#open-io").click(function (){
        //console.log("asdfasdf");
        $("#navi").addClass("expand");
    });

    $("#close-io").click(function (){
        //console.log("asdfasdf");
        $("#navi").removeClass("expand");
    });
});

$(document).ready(function() {
    $(".fancybox").fancybox();
});

平滑滚动正在运行,但是fancybox无法正常工作。帮助我。 我是新手,可能很难理解。

这是我的身体/身体

<script src="js/modernizr.custom.37797.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jQuery.scrollSpeed.js"></script>
<script src="js/parallax.js"></script>

<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="fancybox/source/jquery.fancybox.pack.js"></script>
<script src="fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>

<script type="text/javascript">
  $(function() {
    jQuery.scrollSpeed(1920, 800);
  });

  $(document).ready(function(e) {
    $("#open-io").click(function() {
    //console.log("asdfasdf");
    $("#navi").addClass("expand");
  });

  $("#close-io").click(function() {
    //console.log("asdfasdf");
    $("#navi").removeClass("expand");
  });
</script>

<script type="text/javascript">
  $(document).ready(function() {
    $(".fancybox").fancybox();
  });
</script>

这是链接

<link rel="stylesheet" href="fancybox/source/jquery.fancybox.css" type="text/css" media="screen"/>

这是控制台显示的内容,

Horizontal_MouseWheel_Parallax.html:6 GET file:///C:/fancybox/source/jquery.fancybox.css net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:217 GET file:///C:/js/modernizr.custom.37797.js net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:218 GET file:///C:/js/jQuery.scrollSpeed.js net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:219 GET file:///C:/js/parallax.js net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:221 GET file:///C:/fancybox/lib/jquery.mousewheel-3.0.6.pack.js net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:222 GET file:///C:/fancybox/source/jquery.fancybox.pack.js net::ERR_FILE_NOT_FOUND Horizontal_MouseWheel_Parallax.html:227 Uncaught TypeError: jQuery.scrollSpeed is not a function(anonymous function) @ Horizontal_MouseWheel_Parallax.html:227j @ jquery-latest.min.js:2k.fireWith @ jquery-latest.min.js:2m.extend.ready @ jquery-latest.min.js:2J @ jquery-latest.min.js:2

2 个答案:

答案 0 :(得分:1)

这可能是一些事情,但我会采取以下措施来解决问题:

1)重新排列JavaScript导入,如下所示。此外,向源路径添加前导斜杠(/),否则导入将无法在嵌套页面上运行(您应使用绝对路径,您的路径当前 relative < /强>)。

(我还删除了一个重复的jQuery导入)

<link rel="stylesheet" href="/fancybox/source/jquery.fancybox.css" type="text/css" media="screen" />    

<script src="http://code.jquery.com/jquery-latest.min.js"></script>   
<script src="/js/modernizr.custom.37797.js"></script> 
<script src="/js/jQuery.scrollSpeed.js"></script>
<script src="/js/parallax.js"></script>

<script src="/fancybox/lib/jquery.mousewheel-3.0.6.pack.js"></script>
<script src="/fancybox/source/jquery.fancybox.pack.js"></script>

2)将JavaScript合并到一个$(document).ready函数中:

(我还将您的.click处理程序更新为推荐的.on处理程序

// This could also start with the following line
// $(function() {
$(document).ready(function() {   

  jQuery.scrollSpeed(1920, 800);
  $(".fancybox").fancybox();

  $("#open-io").on('click', function (){
    //console.log("asdfasdf");
    $("#navi").addClass("expand");
  });

  $("#close-io").on('click', function (){
    //console.log("asdfasdf");
    $("#navi").removeClass("expand");
  });

});

试试这个,看看是否有帮助。

让我知道你发现了什么。

答案 1 :(得分:0)

好。我刚刚做得很好。

所以我重新安排了JQuery,我也删除了其中一个

[a-z]{2}

所以整体看起来像这样

jquery.min.js

对于<script src="js/modernizr.custom.37797.js"></script> <script src="js/jquery.min.js"></script> <script src="js/jQuery.scrollSpeed.js"></script> <script src="js/parallax.js"></script> <link rel="stylesheet" href="fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen" /> <script type="text/javascript" src="fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script> ,我也使用你帮我安排好的那个。

$(document).ready(function() {

而且我也没有在我的道路上添加斜线。如果我添加它,它将无法正常工作。

工作

$(document).ready(function() {   

jQuery.scrollSpeed(1920, 800);
$(".fancybox").fancybox();

$("#open-io").on('click', function (){
 //console.log("asdfasdf");
 $("#navi").addClass("expand");
});

$("#close-io").on('click', function (){
 //console.log("asdfasdf");
 $("#navi").removeClass("expand");
});

});

不工作

fancybox/source/jquery.fancybox.pack.js