繁体   English   中英

Typed.js 分号故障

[英]Typed.js semicolon glitch

我在我的网站上使用 Typed.js 来循环浏览一堆关于志愿服务的名言。 当我看到它运行时,一切都在按照它应该的方式工作。 直到带有分号的引用出现。 当它输入时,一切都很好,但是当它取消输入时,它会正常取消输入,直到它到达分号。 当它到达分号时,它只是完全删除了整行,而不是继续取消键入它的 animation。

这是我的代码:

var data = {
  strings: ["“<i>As you grow older, you will discover that you have two hands — one for helping yourself; the other for helping others.</i>” — Audrey Hepburn", "“<i>Never doubt that a small group of thoughtful, committed citizens can change the world; indeed, it’s the only thing that ever has.</i>”  – Margaret Mead", "“<i>The best way to find yourself is to lose yourself in the service of others.</i>” – Gandhi", "“<i>Volunteering is at the very core of being a human.  No one has made it through life without someone else’s help.</i>” – Heather French Henry", "“<i>Volunteerism is the voice of the people put into action.  These actions shape and mold the present into a future of which we can all be proud.</i>” – Helen Dyer"],
  typeSpeed: 40,
  backSpeed: 20,
  shuffle: true,
  loop: !0
};
new Typed('.animated-text', data);

这是一个小视频来证明这一点:

https://im3.ezgif.com/tmp/ezgif-3-425cf91d8c.gif

正如您在 gif 中看到的那样,带有分号的引号输入得很好,但是当它退格或取消输入时,它直到分号才取消输入,只是删除了该行。 当它继续下一个引号时,一个没有分号的引号,它输入和取消输入就好了。

我的问题是为什么会发生以及如何解决这个问题。

谢谢! 任何回应表示赞赏!

您可以通过将分号编码为 html 实体变体&#59;来解决此问题 .
这是因为typed.js看到一个分号并尝试将该分号之前的字符解析为 html 实体,并且由于没有符号来指示此类 html 实体的开始,因此它删除了 Z65E88968 的 Z65E88968 字符串。
与符号和半符号(不正确)解析为 html 实体的示例
你的例子

var data = {
  strings: ["“<i>As you grow older, you will discover that you have two hands — one for helping yourself&#59; the other for helping others.</i>” — Audrey Hepburn", "“<i>Never doubt that a small group of thoughtful, committed citizens can change the world&#59; indeed, it’s the only thing that ever has.</i>”  – Margaret Mead", "“<i>The best way to find yourself is to lose yourself in the service of others.</i>” – Gandhi", "“<i>Volunteering is at the very core of being a human.  No one has made it through life without someone else’s help.</i>” – Heather French Henry", "“<i>Volunteerism is the voice of the people put into action.  These actions shape and mold the present into a future of which we can all be proud.</i>” – Helen Dyer"],
  typeSpeed: 40,
  backSpeed: 20,
  loop: !0
};
new Typed('.animated-text', data);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM