<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js练习三标题栏文字滚动</title>
<script type="text/javascript">
var direction='left';
window.οnlοad=function(){
setInterval(function(){
var titleText,firstChar,others;
titleText=document.title;
if (direction=='left') {
//默认向左滚
firstChar=titleText.charAt(0);
others=titleText.substring(1);
document.title=others+firstChar;
}else{
//向右滚
firstChar=titleText.charAt(titleText.length-1);
others=titleText.substring(0,titleText.length-1);
document.title=firstChar+others;
}
},1000);
//注册单机事件
document.getElementById('btnLeft').οnclick=function(){
direction='left';
};
document.getElementById('btnRight').οnclick=function(){
direction='right';
};
};
</script>
</head>
<body>
<input type="button" name="button" value="left" id="btnLeft">
<input type="button" name="button" value="right" id="btnRight">
</body>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js练习三标题栏文字滚动</title>
<script type="text/javascript">
var direction='left';
window.οnlοad=function(){
setInterval(function(){
var titleText,firstChar,others;
titleText=document.title;
if (direction=='left') {
//默认向左滚
firstChar=titleText.charAt(0);
others=titleText.substring(1);
document.title=others+firstChar;
}else{
//向右滚
firstChar=titleText.charAt(titleText.length-1);
others=titleText.substring(0,titleText.length-1);
document.title=firstChar+others;
}
},1000);
//注册单机事件
document.getElementById('btnLeft').οnclick=function(){
direction='left';
};
document.getElementById('btnRight').οnclick=function(){
direction='right';
};
};
</script>
</head>
<body>
<input type="button" name="button" value="left" id="btnLeft">
<input type="button" name="button" value="right" id="btnRight">
</body>
</html>