繁体   English   中英

未捕获的TypeError:undefined不是函数(jQuery和jQuery Easing)

[英]Uncaught TypeError: undefined is not a function (jQuery & jQuery Easing)

我正在建立一个站点。 我建立了后端,现在在做前端。 在前端,我有引导程序,各种字体真棒图标和棱角分明。 还应注意,这是一个Rails应用程序。

我想使用jQuery&jQuery easing添加1页滚动功能,该功能由超棒的字体提供支持。 我显然做得不好,因为使用时它变成蓝色(由于href可能被认为是“活动状态”?),并且页面上的所有字体(所有内容)都变成了蓝色。

在chrome的控制台中,出现错误;

Uncaught TypeError: undefined is not a function

在jQuery中指的是这一行(可能是任意的);

this.pos = eased = jQuery.easing[ this.easing ](

这是我其余的代码;

index.html.erb

<div class="page-scroll" id="arrow"><a href="#clients"><i class="fa fa-chevron-down"></i><a></div>

styles.css

  #arrow {
    font-size: 25px;
    color: grey;
}

main.js

    $(function() {
      $('.page-scroll a').bind('click', function(event){
         $('html, body').animate({
             scrollTop: $("#clients").offset().top
         }, 1500);
         event.preventDefault();
     });
  });

application.html.erb(由于另一个SO问题,放在样式表下的jQuery和jQuery Easing)

<!-- Easing for Page Scroll -->
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>

当我注释掉索引中的div时,所有字体都恢复正常(激活时为蓝色)。 当我单击按钮时,它将带我到所需的元素,但是将您放到那里,它没有缓动方面(这就是为什么要添加缓动的原因)。

我已经搜索了相当多的内容,对此感到困惑(尤其是文本的更改)。 任何帮助将不胜感激。

从那以后,我就找出了造成这种情况的原因。

发生这种情况时,即使页面被调用,您的页面也找不到jQuery。 要解决此问题,请确保页面内容看起来像这样(对于Rails,所有这些都在application.html.erb中 );

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Good SEO.">
    <meta name="author" content="">

    <title>Your Title</title>

    <!-- Bootstrap Core CSS for smaller projects/single page I'll use a CDN -->
    <link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" type="text/css">

    <!-- Fonts -->
    <link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel='stylesheet' type='text/css'>
    <link href="https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet" type='text/css'>

    <!-- CSS or in assets/stylesheets-->
    <link href="/assets/styles.css" media="screen" rel="stylesheet">

</head>

关闭body和html标签后

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js">
</body>    
</html>

我注意到订单必须是jQuery,引导程序(如果正在使用),然后是jquery.easing。

暂无
暂无

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

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