猿问

带有多行和 html 标签的 javascript 类型编写器

我需要一个 javascript 效果来模拟网站上的打字机


我找到了一个很棒的 codepen: https ://codepen.io/stevn/pen/jEZvXa


问题是我无法输出任何 html 标签(比如物理打印 < 和 > 符号)


示例输出


<html>

<body>

<p>test</p>

我尝试将选项“writingTag”设置为 true,但不起作用。


编辑:我试过 & lt; e> 但没有


炎炎设计
浏览 95回答 1
1回答

德玛西亚99

您是否尝试过使用带有“typewriter”id 属性的 pre 标记将 html 括起来,例如示例?尝试删除这行代码if (HTML[cursorPosition] === "<") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tempTypeSpeed = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (tagOpen) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tagOpen = false;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writingTag = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tag = "";&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tagOpen = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; writingTag = true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tag += HTML[cursorPosition];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答