看到一些无良的网页游戏标题闪动的效果,感觉有些好玩,看了一下JS源代码,原来很简单(本来觉得很神奇的)。
后来想到有些消息提醒也用的到这个效果的,网上又找了个例子,给用的着的童鞋参考吧。
例子1:
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>毛蛋网(maoegg)年度最佳网页游戏,不得不玩!</title>
<script type=”text/javascript”>
var _title = document.title;
var _space = ”;
var isshow = false;for(var i=0; i<=_title.length; i+=2){_space += ‘ ’;}
function flash_title(){if(isshow){document.title = _title; isshow=false;}else{ document.title = _space;isshow = true;}}
setInterval(“flash_title()”,500);
</script>
</head>
<body>
</body>
</html>
例子2:
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>毛蛋网(maoegg.com)</title>
</head>
<script type=”text/javascript”>
var g_blinkswitch = 0;
var g_blinktitle = document.title;
function blinkNewMsg()
{
document.title = g_blinkswitch % 2==0 ? “【 】 – ” + g_blinktitle : “【1条新消息】 – ” + g_blinktitle;
g_blinkswitch++;}
setInterval(blinkNewMsg, 1000);
</script>
<body>
</body>
</html>
例子3:(这个效果更…)
<html>
<head>
<title>毛蛋网(maoegg.com)</title>
</head>
<script type=”text/javascript”>
var titleCont = new Array (
“欢迎光临毛蛋网”,”maoegg.com”,”xhot欢迎你!”
); //数组中的文本即标题
var num=3; //这个跟上面数组长度相同
var i=1;
var j=0;
var k=1; //这3个变量的初始值要对
function xhot_title()
{
window.document.title=titleCont[j].substr(0, i)+”_”;
if (k==0) i–;
if (k==1) i++;
if (i==-1) {k=1;i=0;j++;j=j%num;}
if (i==titleCont[j].length+10) {k=0;i=titleCont[j].length;}parent.window.document.title=titleCont[j].substr(0, i)+”_”;
setTimeout(“xhot_title()”,100); //闪烁速度为100毫秒
}
xhot_title();
</script>
<body>
</body>
</html>
文章来源:毛蛋网(maoegg.com)




评论
发表评论 反向链接