首页 > Web开发 > 详细

JS实现打字效果

时间:2014-02-16 20:34:49      阅读:531      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣

效果见: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>


JS实现打字效果

原文:http://blog.csdn.net/withiter/article/details/19261821

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!