html
1 <ul id="skin"> 2 <li id="skin_0" title="蓝色" class="selected">蓝色</li> 3 <li id="skin_1" title="紫色">紫色</li> 4 <li id="skin_2" title="红色">红色</li> 5 <li id="skin_3" title="天蓝色">天蓝色</li> 6 <li id="skin_4" title="橙色">橙色</li> 7 <li id="skin_5" title="淡绿色">淡绿色</li> 8 </ul>
css
1 /*切换皮肤样式*/ 2 #skin { 3 float:right; 4 margin:10px; 5 padding:4px; 6 120px; 7 list-style:none; 8 border: 1px solid #CCCCCC; 9 background:#FFF; 10 } 11 #skin li { 12 float:left; 13 margin-right:4px; 14 15px; 15 height:15px; 16 text-indent:-9999px; 17 overflow:hidden; 18 display:block; 19 cursor:pointer; 20 background-image:url(../images/theme.gif); 21 } 22 #skin_0 { background-position:0px 0px; } 23 #skin_1 { background-position:15px 0px; } 24 #skin_2 { background-position:35px 0px; } 25 #skin_3 { background-position:55px 0px; } 26 #skin_4 { background-position:75px 0px; } 27 #skin_5 { background-position:95px 0px; } 28 #skin_0.selected { background-position:0px 15px; } 29 #skin_1.selected { background-position:15px 15px; } 30 #skin_2.selected { background-position:35px 15px; } 31 #skin_3.selected { background-position:55px 15px; } 32 #skin_4.selected { background-position:75px 15px; } 33 #skin_5.selected { background-position:95px 15px; }
雪碧图
直接上js
引用了一个jquery.cookie.js //网站换肤 $(function(){ var $li=$("#skin li"); $li.click(function(){ switchSkin(this.id); }) var cookie_skin = $.cookie("MyCssSkin"); if (cookie_skin) { switchSkin( cookie_skin ); } }) function switchSkin(skinName){ $("#"+skinName).addClass('selected').siblings().removeClass('selected'); $("#cssfile").attr("href","styles/skin/"+skinName+".css"); $.cookie("MyCssSkin",skinName,{path:'',expires:10}); }
来源:锋利的jquery