关于网页实现打字机效果的一点问题

2016-03-21 17:01:10 +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>
2015 次点击
所在节点    jQuery
6 条回复
Mirachael
2016-03-22 10:08:45 +08:00
可以的啊
Howcouleyoubeso
2016-03-22 14:42:52 +08:00
@mojixiang1102 你那里能显示吗 为什么我这不行。。
Mirachael
2016-03-23 12:30:45 +08:00
Howcouleyoubeso
2016-03-23 13:20:01 +08:00
@mojixiang1102 不知道为什么 在 Sublime 编辑后没效果..
Mirachael
2016-03-23 23:08:10 +08:00
@Howcouleyoubeso 要引入 jquery 的啊 ,这点不用说吧。
Howcouleyoubeso
2016-03-24 10:24:33 +08:00

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

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

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

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

© 2021 V2EX