在网站上做了一个Tag页面,希望每一个Tag做不同的大小和颜色,以便看起来不是那么一成不变,那么呆板的样式。这种效果在各个CMS中都可以使用,只是需要微调一下部分代码,本效果主要通过jquery加不通尺寸文字大小和不通字体颜色的CSS样式来实现。
下面是通过jquery来实现的特效代码:
<script src="http://lib.sinaapp.com/js/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
var tags_a = $("#tags a");
tags_a.each(function(){
var x = 9;
var y = 0;
var rand = parseInt(Math.random() * (x - y + 1) + y);
$(this).addClass("tags"+rand);
});
})
</script>
下面是CSS的样式表代码:
css代码如下:
<style>
body,a{ font-size:13px;}
a{ color:#333333; text-decoration:none;}
.taglist{ width:250px;overflow:hidden;border:#dddddd solid 1px;}
.taglist .tit{ width:100%; height:24px; line-height:24px; background-color:#565662;}
.taglist .tit a{ padding-left:8px; color:#ffffff;}
#tags a{height:26px; line-height:26px;padding-right:6px;}
#tags .tags0{}
#tags .tags1{color:#C00; font-size:24px;}
#tags .tags2{color:#030; font-size:16px;}
#tags .tags3{color:#00F;}
#tags .tags4{ font-size:16px;}
#tags .tags5{color:#C00; font-size:20px;}
#tags .tags6{color:#F06 font-size:20px;}
#tags .tags7{color:#030; font-weight:bold; font-size:18px;}
#tags .tags8{color:#F06; font-weight:bold;}
#tags .tags9{color:#C00; font-weight:bold;font-size:16px;}
#tags a:hover{ color:#F00; text-decoration:underline;}
.w95{ width:95%; margin:0 auto; padding-top:6px; padding-bottom:6px;}
.taglist .w95{}
</style>
最后是HTML代码:
<div class="tit"><a href="#">TAG标签</a></div>
<div class="w95" id="tags">
<a href='http://www.dazhangli.com/tag/seo/'>搜索引擎优化</a>
<a href='http://www.dazhangli.com/tag/wordpress/'>wordpress</a>
<a href='http://www.dazhangli.com/tag/seoer/'>seoer</a>
</div>
就可以实现如图的Tag标签随机颜色和字号大小效果了!