我想让标题文本可滚动,我让它下面的代码滚动得很好,但我输入的文字显示没有空格,这意味着不考虑字符串中的空格。
<script type="text/javascript">
//function for tittle scrolling
function scrlsts() {
//var scrltest = " Nature ";
scrltest=document.title;
//alert(scrltest);
scrltest = scrltest.substring(1, scrltest.length) + scrltest.substring(0, 1);
//alert(scrltest);
document.title = scrltest;
setTimeout("scrlsts()", 1000);
}
$(document).ready(function() {
var scrltest = " Nature dff ssfd ";
document.title=scrltest;
scrlsts();
});
</script>
提前致谢
答案 0 :(得分:13)
很长一段时间没有制作这些,but this should work:
(function titleScroller(text) {
document.title = text;
setTimeout(function () {
titleScroller(text.substr(1) + text.substr(0, 1));
}, 500);
}(" Nature dff ssfd "));
答案 1 :(得分:2)
我做了一个简单而简单的JavaScript library来完成这项任务。
答案 2 :(得分:1)
<script type='text/javascript'>
title = "Your Title";
position = 0;
function scrolltitle() {
document.title = title.substring(position, title.length) + title.substring(0, position);
position++;
if (position > title.length) position = 0;
titleScroll = window.setTimeout(scrolltitle,170);
}
scrolltitle();
</script>
要停止标题滚动,只需运行:
window.clearTimeout(titleScroll);
答案 3 :(得分:0)
你可以试试这个:
<script>
var repeat=0 //enter 0 to not repeat scrolling after 1 run, othersise, enter 1
var title=document.title
var leng=title.length
var start=1
function titlemove()
{
titl=title.substring(start, leng) + title.substring(0, start)
document.title=titl
start++
if (start==leng+1`enter code here`)
{
start=0
if (repeat==0)
return
}
setTimeout("titlemove()",500)
}
if (document.title)
titlemove()
</script>