javascript - 跳过按钮 - 如何用另一个功能停止一个功能
问题描述
我有两个功能。第一个功能是使用 typed.js 在 div (.con) 中写入一些文本。然后我有一个跳过按钮和另一个功能,它应该停止输入并只显示文本。
HTML:
<button onclick="skip()">skip</button>
Javascript:
function typing() {
$(.con).typed({
strings: ["text"],
stringsElement: null,
typeSpeed: 30,
startDelay: 400,
showCursor: false,
cursorChar: "|",
attr: null,
contentType: 'html',
});
}
function skip() {
$(".con").html("TEXT");
}
问题是即使它显示了文本,它也会消失,因为 typed.js 仍在编写文本。我不知道用这个功能停止以前的功能。
解决方案
更改您的代码以调用这样的键入停止方法,以防止它继续放入文本并允许您设置它:
function typing() {
window.conTyped = $(".con").typed({
strings: ["text"],
stringsElement: null,
typeSpeed: 30,
startDelay: 400,
showCursor: false,
cursorChar: "|",
attr: null,
contentType: 'html',
});
}
function skip() {
window.conTyped.stop();
$(".con").html("TEXT");
}
推荐阅读
- c - i2c 传输,stm32f103 作为 Master,STOP 条件生成问题
- c# - 在 ASP.Net 中实现和生成多个动态 SiteMapNode
- json - 使用 `curl` 的 API 调用在 Swift 中不起作用
- jquery - 另一个表单的另一个 ajax 函数不起作用
- css - 如何显示行的交替红色和绿色?
- python - 如何获得方向
在tkinter? - c - 为什么 scanf_s 不能在 Visual Studio 以外的任何地方工作?
- c++ - r 值引用是如何在这里传递的?
- javascript - 为什么我的搜索查询结果不佳?
- c++ - 为什么 clang 不能将元组的构造限制为显式?