js css 仿QQ網站換膚效果代碼

來源:互聯網
上載者:User

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>js css 仿qq網站換膚效果代碼</title>
<script language="網頁特效">
//設定cookie,按鈕選中狀態,頁麵皮膚   
skin.setskin=function(n){   
var skins =("skin").getelementsbytagname("li");   
for (i=0;i
{   
skins[i].classname="";//初始化按鈕狀態   
}   
skin.setcookie(n);//儲存當前樣式   
("skin_"+n).classname="selected";//設定選中皮膚按鈕的樣式   
("cssfile").href="css/main"+n+".css";//設定頁面樣式   
}  

//cookie

skin.setcookie=function(n){   
var expires=new date();   
expires.settime(expires.gettime()+24*60*60*365*1000);   
var flag="skin_cookie="+n;   
document.cookie=flag+";expires="+expires.togmtstring();   
}   
//返回使用者佈建的皮膚樣式   
skin.readcookie=function(){   
var skin=0;   
var mycookie=document.cookie;   
var name="skin_cookie";   
var start1=mycookie.indexof(name+"=");   
if(start1==-1){   
skin=0;//如果沒有設定則顯示預設樣式   
}   
else{   
var start=mycookie.indexof("=",start1)+1;   
var end=mycookie.indexof(";",start);   
if(end=-1){   
end=mycookie.length;   
}   
var values= unescape(mycookie.substring(start,end));   
if (values!=null)   
{   
skin=values;   
}   
}   
return skin;   
  
}  

//js換膚事情

skin.addevent=function(){   
var skins =("skin").getelementsbytagname("li");   
for (i=0;i
{   
skins[i].onclick=function(){skin.setskin(this.id.substring(5))};   
}   

//載入效果

window.onload=function(){   
skin.setskin(skin.readcookie());//根據讀取cookie傳回值設定皮膚樣式   
skin.addevent();//綁定按鈕事件
</script>
</head>

<body>
<ul id="skin">    
<li id="skin_0" title="灰色">灰色li>  
<li id="skin_1" title="綠色">綠色li>  
<li id="skin_2" title="黃色">黃色li>  
<li id="skin_3" title="藍色">藍色li>  
<li id="skin_4" title="粉色">粉色li>  
<li id="skin_5" title="紫色">紫色li>  
<ul>  

</body>
</html>

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.