首页 > 编程语言 > 详细

javascript走马灯的效果(文档标题文字滚动)

时间:2016-09-07 13:00:53      阅读:223      评论:0      收藏:0      [点我收藏+]

做一些网站的时候,文档标题会滚动,这个效果是走马灯的效果。

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>走马灯的效果</title>
	</head>
	<body>
		<script>
			var dir="";
			function zouma(){
				var tit=document.title;
				if(dir=="left"){
					var first=tit.substring(0,1);
					//console.log(first);
					var last=tit.substring(1,tit.length);
					document.title=last+first;
				}else if(dir=="right"){
					var first=tit.substring(0,tit.length-1);
					console.log(first);
					var last=tit.substring(tit.length-1);
					document.title=last+first;
				}
			}
			function strdir(d){
				dir=d;
			}
			setInterval("zouma()",600);
		</script>
		<button id="left" type="button" onclick="strdir(‘left‘)">向右滑动</button>
		<button id="right" type="button" onclick="strdir(‘right‘)">向左滑动</button>
	</body>
</html>

  这个分为向左滚动和向右滚动,默认不滚动

javascript走马灯的效果(文档标题文字滚动)

原文:http://www.cnblogs.com/taiyanghua0522/p/5848909.html

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