JS里的走马灯效果
<!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>1234567</title>
<script type="text/javascript">
var IntervalId;
function scroll2left() {
var title = document.title;
//取第一个字符
var firstch = title.charAt(0);
var leftstr = title.substring(1, title.length);//易出错 注意
title = leftstr + firstch;
document.title = title;
}
function scroll2right() {
var title = document.title;
//取最右边的字符
var lastch = title.charAt(title.length-1);
var leftstr = title.substring(0, title.length-1);
document.title = lastch + leftstr;
}
// scroll();
//setInterval(scroll, 500);
// setInterval("scroll2left()", 500);
</script>
</head>
<body onload="IntervalId=setInterval('scroll2left()', 500)">
<input type="button" value="向左滚动" onclick="clearInterval(IntervalId);IntervalId=setInterval('scroll2left()', 500)" />
<input type="button" value="向右滚动" onclick="clearInterval(IntervalId);IntervalId=setInterval('scroll2right()', 500)" />
</body>
</html>