Textillate w/ jQuery不起作用.未捕获的类型错误: $ 未定义

Textillate w/ jQuery not functioning. Uncaught TypeError: $ is not defined

本文关键字:类型 错误 未定义 jQuery 不起作用 Textillate      更新时间:2023-09-26

好吧,我觉得我已经尝试了一切。我知道有很多类似的问题,但我对Javascript不是很熟悉,所以我读过的其他答案远远超出了我的头脑。我得到:

尝试运行 Textillate 脚本时Uncaught ReferenceError: $ is not defined

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
  <?php include('head.php'); ?>

<!-- Bootstrap -->
<link href="css/bootstrap.min.css" type="text/css" rel="stylesheet">
<link href="css/custom.css?version=1.4" type="text/css" rel="stylesheet">
<link href="css/animate.css" type="text/css" rel="stylesheet">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js" async></script>
<script type="text/javascript" src="js/bootstrap.min.js" async></script>
<script type="text/javascript" src="js/jquery.lettering.js" async></script>
<script type="text/javascript" src="js/jquery.textillate.js" async></script> 
<script>
$(function() {
             $('.txt').textillate({ 
  in: { effect: 'rollIn' },
  out: { effect: 'foldUnfold', sync: true },
  loop: true
         });
 </script>

我已经按照文档的指示在<head>中加载了最新版本的jQuery,animate.css,textillate.js和lettering.js。

我的HTML是这样的:

<h1 class="txt" data-in-effect="rollIn">text</h1>

有人可以用最简单的术语告诉问题所在以及如何解决此错误吗?

我错过的东西可能是显而易见的,但就像我说的,我是一个菜鸟。现场演示可以在这里找到:www.thekdesignco.com/new/

第一个问题是:sript-tags中的async-属性。使用async HTML解析器不会等到脚本加载完毕。所以 DOM 首先准备好了,$(function() {})在 jQuery 出现之前被执行。

第二个问题:上一个脚本中的函数未正确关闭。它必须看起来像:

$(function() {
     $('.txt').textillate({ 
         in: { effect: 'rollIn' },
         out: { effect: 'foldUnfold', sync: true },
         loop: true
     });
});

请立即修复它。

第三个问题:某个地方<太多或错误的地方。这似乎是jquery.textillate.js文件中的问题。当我找到它时,我会更新这个答案。

编辑js/jquery.textillate.js中的文件不是jquery.textillate.js而是一些未知的HTML文件。清理你的js-folder.

using jquery.noconflict();

将解决问题。