jquery标签【无规则标签云样式】

2017-06-12  本文已影响0人  平凡执着

jquery制作一个简单的标签云无规则样式,每次页面刷新展示的标签云样式都不一样。通过随机分配样式类名称,来实现多种标签云样式排列

<script type="text/javascript">
$(document).ready(function(){
    /*随机取颜色*/
    var tags_a = $("#tags").find("a");
    tags_a.each(function(){
        var x = 9;
        var y = 0;
        var rand = parseInt(Math.random() * (x - y + 1) + y);
        $(this).addClass("size"+rand);
    });
});
</script>

<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
body{font:12px/180% Arial, Helvetica, sans-serif ,"宋体";}

.demo{background:#FFF8DE;border:solid 1px #ff6600;width:380px;margin:20px auto;}
.demo h2{font-size:18px;height:32px;padding:10px 0 0 20px;font-family:"微软雅黑","宋体";border-bottom:solid 1px #ff6600;}
.taglist{padding:20px 20px 30px 20px;}
.taglist a{padding:3px;display:inline-block;white-space:nowrap;}
a.size1{font-size:25px;padding:10px;color:#804D40;}
a.size1:hover{color:#E13728;}
a.size2{padding:7px;font-size:20px;color:#B9251A;}
a.size2:hover{color:#E13728;}
a.size3{padding:5px;font-size:35px;color:#C4876A;}
a.size3:hover{color:#E13728;}
a.size4{padding:5px;font-size:15px;color:#B46A47;}
a.size4:hover{color:#E13728;}
a.size5{padding:5px;font-size:25px;color:#E13728;}
a.size5:hover{color:#B46A47;}
a.size6{padding:0px;font-size:12px;color:#77625E}
a.size6:hover{color:#E13728;}
</style>

<div class="demo">
    <h2>jQuery 标签云 <span style="color:#3366cc;">F5刷新试试</span></h2>
    <div class="taglist" id="tags">
        <a target="_blank" href="http://www.17sucai.com/">菜单</a><a target="_blank" href="http://www.17sucai.com/">无缝滚动</a><a target="_blank" href="http://www.17sucai.com/">焦点图</a><a target="_blank" href="http://www.17sucai.com/">上下滚动</a><a target="_blank" href="http://www.17sucai.com/">左右滚动</a><a target="_blank" href="http://www.17sucai.com/">滚动条</a><a target="_blank" href="http://www.17sucai.com/">文字 滚动</a><a target="_blank" href="http://www.17sucai.com/">图片滚动</a><a target="_blank" href="http://www.17sucai.com/">弹出层</a><a target="_blank" href="http://www.17sucai.com/">浮动层</a><a target="_blank" href="http://www.17sucai.com/">html5</a><a target="_blank" href="http://www.17sucai.com/">div 布局</a><a target="_blank" href="http://www.17sucai.com/">flash动画</a><a target="_blank" href="http://www.17sucai.com/">表单 提交</a><a target="_blank" href="http://www.17sucai.com/">选项卡</a><a target="_blank" href="http://www.17sucai.com/">二级导航</a><a target="_blank" href="http://www.17sucai.com/">表格</a>   
    </div>
</div>
上一篇下一篇

猜你喜欢

热点阅读