JS实现打字效果

最近参加了CSDN论坛举办的214情人节活动,就写个了页面,


效果见:http://withiter.com/cross.jsp

这里我把代码共享出来,供大家参考:

<html>
<head>
<title>I just wanna stay</title>
<style type="text/css">
a {
	text-decoration: none
}
</style>
</head>
<body>
	<div id="newsticker">
		<span id="tickertitle"></span><span style="color:green;" id="typewriter"
			href="javascript:void(0);"></span>
	</div>
</body>
</html>
<script type="text/javascript">
	var current = 0;
	var x = 0;
	var speed = 100;
	var speed2 = 10000;
	function initArray(n) {
		this.length = n;
		for ( var i = 1; i <= n; i++) {
			this[i] = ' ';
		}
	}
	typ = new initArray(16);
	typ[0] = "1) Do you have a map? Because I just keep losing in your eyes.<br/><br/>"
			+ "2) Meeting you was fate,and falling in love with you was out of my control.<br/><br/>"
			+ "3) No man or woman is worth your tears and the one who is,won't make your cry.<br/><br/>"
			+ "4) There are two reasons why I wake up in the morning: my alarm clock and you.<br/><br/>"
			+ "5) You are everything to me, and I was so blessed when god sent you here for me<br/><br/>"
			+ "6) In spite of you and me and the silly world going to pieces around us,I love you.<br/><br/>"
			+ "7) If I could rearrange the alphabet,I'd put Y and I together.<br/><br/>"
			+ "8) It's not being in love that makes me happy, but is being in loving with you.<br/><br/>"
			+ "9) There are 4 steps to happiness: 1 you 2 me 3 our hearts 4 together<br/><br/>"
			+ "10) Love you so I don`t wanna go to sleep, for reality is better than a dream.<br/><br/>"
			+ "2014/2/14  Cross, Follow me at SinaWeibo <a target='_blank' href='http://weibo.com/343642038'>http://weibo.com/343642038</a><br/><br/>";
			
	function typewrite() {
		var m = typ[current];
		document.getElementById("typewriter").innerHTML = m.substring(0, x++)
				+ "_";

		if (x == m.length + 1) {
			x = 0;
			current++;
			if (current > typ.length - 1) {
				current = 0;
			}
		} else {
			setTimeout("typewrite()", speed);
		}
	}
	typewrite();
</script>


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值