簡體   English   中英

打字機效果不起作用

[英]Typewriter effect not working

每當我運行此代碼時,我只會在屏幕上看到背景色。
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異常:$(...)。typed不是函數TypeError:$(...)。typed不是HTMLDocument的函數。 (localhost / resume / typed.html:23:14)在進程(code.jquery.com/jquery-3.2.1.js)上的mayThrow(code.jquery.com/jquery-3.2.1.js:3583:29) :3651:12)未定義jQuery.Deferred.exceptionHook @ jquery-3.2.1.js:3860 jquery-3.2.1.js:3869 Uncaught TypeError:$(...)。typed在HTMLDocument中不是函數。 (typed.html:23)在進程(jquery-3.2.1.js:3651)的maythThrow(jquery-3.2.1.js:3583)

您使用的語法錯誤,請嘗試以下代碼:

 <!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>

該錯誤是因為您的jQuery插件未在typed.js之前加載。 由於工作正常,否則您應該查看是否

 <script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript"></script> <script src="https://pastebin.com/raw/RqHC6rCj" type="text/javascript"></script> <body> <div class="center"> <span class="type"></span> </div> <script> $(function(){ $(".type").typed({ strings: [ "Hello", "My Name Is Aditya Aundhekar", "I'm a Computer Engineer..", ], }) }) </script> </body> 

`

只需查看我上載JS插件的片段,即可正常運行。

因此必須首先加載依賴項。 因此,存在一些加載問題。

我將於明天從這里刪除該插件,因此請先檢查一下。 該文件已上傳,因為我無法通過引用添加它。

編輯:我通過鏈接插入了typed.js,而不是將整個插件包含在代碼段中,並從代碼段中刪除了typed.js插件原始文件。 下一個月可用,然后刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM