在Typed.js中的字符串前面获取Backspace

时间:2017-07-05 13:31:02

标签: 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>

1 个答案:

答案 0 :(得分:0)

尝试在回调函数中添加一个删除光标的.first类型函数。 $(&#39; .typed光标&#39)。除去(); 或者document.querySelector(&#39; .typed-cursor&#39;)。remove();

&#13;
&#13;
$(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,

    });

  }
});
&#13;
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;
}
&#13;
<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>
&#13;
&#13;
&#13;