Typed.js 分号错误
Typed.js semicolon glitch
我在我的网站上使用 Typed.js 循环浏览一堆关于志愿服务的引述。当我看到它时 运行,一切都在按预期工作。直到引用带分号的运行通过。当它输入时,一切都很好,但当它取消输入时,它会正常取消输入,直到到达分号。当它到达分号时,它只是完全删除了整行,而不是继续取消输入的动画。
这是我的代码:
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 实体变体 ;
.
的分号进行编码来解决此问题
这是因为 typed.js
看到分号并尝试将该分号之前的字符解析为 html 实体,并且由于没有符号来指示它删除的此类 html 实体的开始字符串的其余部分。
Example of ampersand and semi (incorrectly) parsed as html entity
Your example
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,
loop: !0
};
new Typed('.animated-text', data);
我在我的网站上使用 Typed.js 循环浏览一堆关于志愿服务的引述。当我看到它时 运行,一切都在按预期工作。直到引用带分号的运行通过。当它输入时,一切都很好,但当它取消输入时,它会正常取消输入,直到到达分号。当它到达分号时,它只是完全删除了整行,而不是继续取消输入的动画。
这是我的代码:
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 实体变体 ;
.
的分号进行编码来解决此问题
这是因为 typed.js
看到分号并尝试将该分号之前的字符解析为 html 实体,并且由于没有符号来指示它删除的此类 html 实体的开始字符串的其余部分。
Example of ampersand and semi (incorrectly) parsed as html entity
Your example
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,
loop: !0
};
new Typed('.animated-text', data);