有关 js 的打字机效果问题

2016-03-21 16:28:17 +08:00
 Howcouleyoubeso
我是刚学 js 的新手,想在网页上实现打字机效果,但是却没成功,请各位帮忙看一下,谢谢。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="autotype">This is a test</div>
<script type="text/javascript">
$.fn.autotype = function() {
var $tt = $(this);
var str = $tt.html();
var index = 0;
$(this).html('');
var timer = setInterval(function() {
var current = str.substr(index, 1);

if (current == '<')
index = str.indexOf('>', index) + 1;
else
index++;

$tt.html(str.substring(0, index) + (index & 1 ? '_' : ''));

if (index >= str.length)
clearInterval(timer);
}, 55);
};

$("#autotype").autotype();

</script>
</body>
</html>
1711 次点击
所在节点    JavaScript
2 条回复
wyc829
2016-03-23 10:11:54 +08:00
有效果啊,就是要加上 jquery 就是了.
Howcouleyoubeso
2016-03-23 10:57:43 +08:00
@wyc829 请问怎么加?$("#autotype").autotype(); 我不是已经调用函数了吗?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/265174

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX