仿WEB QQ 有新消息时,滚动窗口标题栏效果。 用了一个闭包的方法来实现。

/**
 * 调用方法
 * TitleFlash.stop();
 * TitleFlash.setTitle(str);
 * TitleFlash.go();
 */
var TitleFlash=(function(){

			var msg="";
			var msgud = " " + msg;
			var T;
			function titleScroll(){

				if (msgud.length < msg.length)
					msgud += " - " + msg;
				msgud = msgud.substring(1, msgud.length);
				document.title = msgud.substring(0, msg.length);
				T=window.setTimeout(function(){titleScroll()},200)
			}
			return{
				setTitle: function(title){
					msg=title;
				},
				go:function(){
					titleScroll();
				},
				stop:function(){
					clearTimeout(T);
				}
			}

		})();
Tagged with:  

Leave a Reply