javascript - 打字机效果不工作

标签 javascript jquery html css

每当我运行这段代码时,除了屏幕上的背景颜色,我什么也得不到。
typed.js 被下载并放在同一个文件夹中。出了什么问题?

 <!DOCTYPE html>
<html>
<head>
    <title>type js</title>

<style type="text/css">
    body{
        margin: 0;
        padding: 0;
        background: #bf1f26;
    }
    .type{
        color: black;
    }
</style>

<script
  src="https://code.jquery.com/jquery-3.2.1.js"> </script>

  <script src="typed.js"></script>
<script type="text/javascript">
    $(function(){
        $(".type").typed({
            strings: [
            "Hello",
            "My Name Is Aditya Aundhekar",
            "I'm a Computer Engineer..",
            ],
        })
    })
</script>
</head>
<body>
<div class="center">
    <span class="type"></span>
</div>
</body>
</html>

我收到这个错误:

jQuery.Deferred exception: $(...).typed is not a function TypeError: $(...).typed is not a function at HTMLDocument. (localhost/resume/typed.html:23:14) at mightThrow (code.jquery.com/jquery-3.2.1.js:3583:29) at process (code.jquery.com/jquery-3.2.1.js:3651:12) undefined jQuery.Deferred.exceptionHook @ jquery-3.2.1.js:3860 jquery-3.2.1.js:3869 Uncaught TypeError: $(...).typed is not a function at HTMLDocument. (typed.html:23) at mightThrow (jquery-3.2.1.js:3583) at process (jquery-3.2.1.js:3651)

最佳答案

你使用了错误的语法,试试这个代码:

 <!DOCTYPE html>
<html>
<head>
    <title>type js</title>

<style type="text/css">
    body{
        margin: 0;
        padding: 0;
        background: #bf1f26;
    }
    .type{
        color: black;
    }
</style>

<script
  src="https://code.jquery.com/jquery-3.2.1.js"> </script>

  <script src="typed.js"></script>
<script type="text/javascript">
    $(function(){
      var options = {
        strings: [
        "Hello",
        "My Name Is Aditya Aundhekar",
        "I'm a Computer Engineer.."]
    }

       var typed = new Typed(".type", options);
    })
</script>
</head>
<body>
<div class="center">
    <span class="type"></span>
</div>
</body>
</html>

关于javascript - 打字机效果不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45245043/

相关文章:

html - 使用 Alpha channel 视频屏蔽 HTML 内容

PHP 在 WAMP 中返回 HTML 标签和 JSON

javascript - 获取 Uncaught Error : [$injector:modulerr] in anuglar. js

javascript - 转换为文本框搜索而不是下拉搜索

javascript - XMLHttpRequest.onreadystatechange 行为异常

javascript - 类型错误 : Cannot read property 'extendedProps' of undefined

jquery - jqgrid 'restoreRow' 在哪里存储其数据?

javascript - 如何结合使用 RegEx 和代码来验证 IPv6 地址?

jQuery 存储对 $(this) 的引用

html - 多行的水平居中流体 div