javascript - 在 Typed.js 中的字符串前面获取退格键

标签 javascript html css performance web

正如我下面关于执行 iam 的代码,在字符串前面固定了一个退格光标。我尝试了一些方法,但没有用。有谁知道如何从字符串的前面删除它。请帮助我

$(function() {
  $("h2 .first").typed({
    strings: ["Hello "],
    typeSpeed: 0,
    callback: function() {
      showThis();
    },

  });

  function showThis() {

    $("span.second").typed({
      strings: ["First", "Second", "Third"],
      backDelay: 1500,
      typeSpeed: 100,
      backSpeed: 100,
      loop: true,

    });

  }
});
body {
  margin: 0;
}

.header {
  height: 100vh;
  background-color: orange;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.typed cursor {
  display: none;
}

h2 {
  color: white;
  font-size: 4.125em;
  font-family: Montserrat, sans-serif;
  text-align: center;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://www.mattboldt.com/demos/typed-js/js/typed.custom.js"></script>
<div class="header">

  <h2><span class="first"></span><span class="second"></span></h2>


</div>

最佳答案

尝试在您的回调中为 .first 类型的函数添加一个函数来移除光标。 $('.typed-cursor').remove(); 或者 document.querySelector('.typed-cursor').remove();

$(function() {
  $("h2 .first").typed({
    strings: ["Hello "],
    typeSpeed: 0,
    callback: function() {
      showThis();
      document.querySelector('.typed-cursor').remove();
    },

  });

  function showThis() {

    $("span.second").typed({
      strings: ["First", "Second", "Third"],
      backDelay: 1500,
      typeSpeed: 100,
      backSpeed: 100,
      loop: true,

    });

  }
});
body {
  margin: 0;
}

.header {
  height: 100vh;
  background-color: orange;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.typed cursor {
  display: none;
}

h2 {
  color: white;
  font-size: 4.125em;
  font-family: Montserrat, sans-serif;
  text-align: center;
}
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://www.mattboldt.com/demos/typed-js/js/typed.custom.js"></script>
<div class="header">

  <h2><span class="first"></span><span class="second"></span></h2>


</div>

关于javascript - 在 Typed.js 中的字符串前面获取退格键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44927712/

相关文章:

javascript - 无法使用DOM获取背景颜色

javascript - 如何在 node.js 中使用 promise 函数的返回值

javascript - 将onchange函数下拉到html中

html - 垂直和横向对齐图标

javascript - 如何在 JavaScript 或 Jquery 中检查 json 字符串是否有效?

javascript - Style Jquery dialog content div 背景混合在对话框中

html - 如何在 Bootstrap 网格中居中放置文本

html - 具有两列的 Css 流体布局

php - 如果使用 php 满足特定条件,则激活禁用链接

css - 如果在小型设备中更改列顺序