本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议,欢迎转载、或重新修改使用,但需要注明来源。 [署名 4.0 国际 (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/deed.zh) 本文作者: 苏洋 创建时间: 2013年06月01日 统计字数: 597字 阅读时间: 2分钟阅读 本文链接: https://soulteary.com/2013/06/01/javascript-scroll-titl.html ----- # JavaScript 标题滚动 闲着无趣,发一个小脚本,有想把以前的VBSCRIPT全部改写过来的冲动。 有的时候我们需要窗口标题闪动或者滚动,那么不妨使用下面的代码。 ```js (function () { var titleScroll = function () { var index = 0; var text = "欢迎光临Story校园相册!"; var len = text.length; var init = function () { document.title = text.substring(0, index + 1); index++; if (index >= len) { index = 0; document.title = text; } setTimeout(arguments.callee, 150); } init(); } titleScroll(); })("http://soulteary.com") ``` 当然有个压缩版本的,使用方法嘛,在最后的括号传递的变量里改为你的提示文本就好。 ```js (function(b){var a=0,c=b.length;(function(){document.title=b.substring(0,a+1);a++;a>=c&&(a=0,document.title=b);setTimeout(arguments.callee,150)})()})("http://soulteary.com"); ```