dede模板實現(xiàn)彩色TAG代碼主要由JS+CSS實現(xiàn)
作用方法:
1、建一個新的*.html文檔,將以下代碼拷進去,然后保存
2、在首頁相應的位置進行調(diào)用
代碼如下:
-
<style type="text/css" >
-
.tagCloud{ padding:0 6px; }
-
.tagCloud a { margin:0 8px 0 0; line-height:22px; }
-
.color0{ color:#2F5FC2; }
-
.color1{ color:#AC1BF2; }
-
.color2{ color:#9E6FC5; }
-
.color3{ color:#FBA426; }
-
.color4{ color:#2739CF; }
-
.color5{ color:#C8A453; }
-
.color6{ color:#AB2846; }
-
.weight0{ font-weight:100; }
-
.weight1{ font-weight:300; }
-
.weight2{ font-weight:500; }
-
.weight3{ font-weight:700; }
-
.weight4{ font-weight:900; }
-
.weight5{ font-weight:bold;}
-
.weight6{ font-weight:bolder; }
-
.size0{ font-size:12px; }
-
.size1{ font-size:13px; }
-
.size2{ font-size:14px; }
-
.size3{ font-size:16px; }
-
.size4{ font-size:20px; }
-
.size5{ font-size:22px; }
-
.size6{ font-size:24px; }
-
</style>
-
<script language="javascript" type="text/javascript">
-
function setTagCloudStyle(){
-
var colors = new Array("color0","color1","color2","color3","color4",
-
"color5","color6");
-
var sizes = new Array("size0","size1","size2","size3");
-
var weights = new Array("weight0","weight1","weight2","weight3",
-
"weight4","weight5","weight6");
-
var colorsLen = colors.length;//獲取顏色樣式個數(shù)
-
var sizesLen = sizes.length;//獲取字體大小樣式個數(shù)
-
var weightsLen = weights.length;//獲取字體粗細樣式個數(shù)
-
-
var tagCloud = document.getElementById("tagCloud");
-
var tagLinks = tagCloud.getElementsByTagName("a");
-
var tagLinksLen = tagLinks.length;
-
for(i = 0 ; i < tagLinksLen ; i++){
-
tagLinks[i].className = colors[Math.floor(colorsLen*Math.random())] + "
-
" + sizes[Math.floor(sizesLen*Math.random())]+ " " + weights[Math.floor(weightsLen*Math.random())];
-
//隨機設(shè)置每個<a>標簽的樣式,以實現(xiàn)不同效果.
-
}
-
}
-
-
if(document.addEventListener){
-
window.addEventListener('load',setTagCloudStyle,false);
-
}else{
-
window.attachEvent('onload',setTagCloudStyle);
-
}
-
//綁定onload事件,在文檔載入完畢啟動setTagCloudStyle()函數(shù);
-
</script>
-
<div class="tagCloud" id="tagCloud">{dede:tag row='20' getall='1' sort='month'}<a href='http://www.dedecms51.com/[field:link/]'>[field:tag /]</a>{/dede:tag}</div>