function newTitle() {
var titleDOM = document.getElementsByTagName("title")[0];
var text = titleDOM.innerHTML;
var cacheTitle = titleDOM.getAttribute("cacheTitle");
if(!cacheTitle){
cacheTitle=text;
document.getElementsByTagName("title")[0].setAttribute("cacheTitle",text);
}
var nLen = cacheTitle.length;
var sEndChar = cacheTitle.substring(nLen-1,nLen);
var nNowIndex = text.indexOf(sEndChar)+1;
text = text.substring(1,nNowIndex);
//log("text = "+text+",sEndChar = "+sEndChar+",nNowIndex ="+nNowIndex);
if(nNowIndex<=0 ||!!text==false){
document.title = cacheTitle;
}else{
document.title = text;
}
// document.title=text.substring(1,text.length)+text.substring(0,1);
setTimeout("newTitle()", 500);
}
愤怒的coder - share
本文介绍了一种使用JavaScript实现网页标题动态变化的方法。通过定时器每隔一段时间截取原始标题的一部分展示为当前页面标题,实现了趣味性的效果。这种方法可以提升用户体验,让页面显得更加生动。
2060

被折叠的 条评论
为什么被折叠?



