日期:2014-05-16 浏览次数:20525 次
<html>
<head>
<title>javascript文字逐字逐行显示效果</title>
<script>
var text = "12345678901234567890123456789012345678901234567890";
var textLen = text.length;
var lineNum = 10; //定义每行显示多少个字
var num = 0;
var _ = document.createTextNode('_');
var i = 0;
function type() {
str = text.substr(i, 1);
var txt = document.getElementById('txt');
txt.appendChild(document.createTextNode(str));
txt.appendChild(_);
num++;
if (num > 0 && num % lineNum == 0) txt.appendChild(document.createElement('br'));
i++;
if (i < textLen) setTimeout(function () { type(i) }, 300); else txt.removeChild(_);
}
</script>
</head>
<body onload="type()">
<div id="txt"></div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
#tcfr {
width: 200px;
height: 300px;
background: #99ccff;
font-size: 20px;
text-indent: 40px;
}
#tcfr p {
margin: 0px;
}
</style>
</head>
<body>
<div id="tcfr">
</div>
<script type="text/javascript">
var str = "想在这个页