javascript实现标签云

发布时间:2013-04-28    发布:Linsj    分类:前端开发

这是一个效果图

原理:随机取色,随机字体大小

实现:

1、随机方法:

JavaScript代码
  1. function rand(num){  
  2.        return parseInt(Math.random()*num+1);  
  3.       }  

2、随机取色:

JavaScript代码
  1. function randomcolor(){  
  2.         var str=Math.ceil(Math.random()*16777215).toString(16);  
  3.         if(str.length<6){  
  4.           str="0"+str;  
  5.         }  
  6.         return str;  
  7.       }  

3、循环dom

XML/HTML代码
  1. for( len=obj.length,i=len;i--;){  
  2.         obj[i].style.left=rand(600)+"px";  
  3.         obj[i].style.top=rand(400)+"px";  
  4.         obj[i].className="color"+rand(5);  
  5.         obj[i].style.zIndex=rand(5);  
  6.         obj[i].style.fontSize=rand(12)+12+"px";  
  7.        // obj[i].style.background="#"+randomcolor();  
  8.         obj[i].style.color="#"+randomcolor();  
  9.         obj[i].onmouseover=function(){  
  10.           this.style.background="#"+randomcolor();  
  11.         }  
  12.         obj[i].onmouseout=function(){  
  13.           this.style.background="none";  
  14.         }  
  15.       }  

4、dom结构

XML/HTML代码
  1. <div id="wrap">  
  2.    <a href="#">web标准学习</a><a href="#">css</a>  
  3.    <a href="#">javascript</a><a href="#">html5</a>  
  4.    <a href="#">canvas</a><a href="#">video</a>  
  5.    <a href="#">audio</a><a href="#">jQuery</a>  
  6.    <a href="#">jQuerymobile</a><a href="#">flash</a>  
  7.    <a href="#">firefox</a><a href="#">chrome</a>  
  8.    <a href="#">opera</a><a href="#">IE9</a>  
  9.    <a href="#">css3.0</a><a href="#">andriod</a>  
  10.    <a href="#">apple</a><a href="#">google</a><a href="#">jobs</a>  
  11.   </div>  

 

查看 [2822]   评论 [0] 
相关标签: 程序开发  网页设计 
文章评论
暂无数据!
我来说两句
昵 称:
评 论:
   
咨询电话:020-61136292 87569708 61004412 61004413
讯博官网 | 走进讯博 | 整合营销 | 案例解读 | 资讯中心 | 案例欣赏 | 产品体验区 | 客户如是说 | 联系我们
版权所有 © 2003-2014 广州讯博网络科技有限公司 粤ICP备08107356号 开心一刻
Website Design & Power by:Cenbel.com