JS--在标题中实现跑马灯的效果

	var time=null;
	timer();
	function timer(){
		$(function(){
            var title=$("title").html();
            var temptitle=title;
            var length=title.length;
            time=setInterval(function(){
                temptitle=temptitle.concat(temptitle.charAt(0));
                length=temptitle.length;
                temptitle=temptitle.substring(1,length);
                $("title").html(temptitle);
            }, 500);
        });
	}
	document.addEventListener('visibilitychange', function () {
	<!--判断如果离开页面时,title变化并清除在页面时跑马灯效果-->
		if (document.visibilityState == 'hidden') {
			normal_title = document.title;
			document.title = '客官请留步...';
			clearInterval(time)
		} else{
	<!--如果在当前页面时,title变化,执行定时器-->
			document.title = normal_title;
			timer();
		} 
	});
原文地址:https://www.cnblogs.com/cyapi/p/15365797.html