新手正在自学 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>
<!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>