正如我下面关于执行 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/