標籤雲代碼分享

mydemo.html

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">    
  4.  
  5. <head>    
  6.  
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
  8.  
  9. <title>標籤雲程序測試</title>    
  10.  
  11. <link rel="stylesheet" type="text/css" href="mystyle.css" />    
  12.  
  13. <script type="text/javascript" src="mycloud.js"></script>    
  14.  
  15. </head>    
  16.  
  17.      
  18.  
  19. <body>    
  20.  
  21. <div id="div1">    
  22.  
  23.     <a href="hhttp://lubcdc.blog.51cto.com/#">Linux</a>    
  24.  
  25.     <a href="http://lubcdc.blog.51cto.com/#" class="red">Oracle</a>    
  26.  
  27.     <a href="http://lubcdc.blog.51cto.com/#">JSP</a>    
  28.  
  29.     <a href="http://lubcdc.blog.51cto.com/#">RedHat</a>    
  30.  
  31.     <a href="http://lubcdc.blog.51cto.com/#" class="blue">AIX</a>    
  32.  
  33.     <a href="http://lubcdc.blog.51cto.com/#">SEO</a>    
  34.  
  35.     <a href="http://lubcdc.blog.51cto.com/#" class="red">CTO</a>    
  36.  
  37.     <a href="http://lubcdc.blog.51cto.com/#" class="yellow">JavaScript</a>    
  38.  
  39.     <a href="http://lubcdc.blog.51cto.com/#">LuBin</a>    
  40.  
  41.     <a href="http://lubcdc.blog.51cto.com/#" class="red">CSS</a>    
  42.  
  43.     <a href="http://lubcdc.blog.51cto.com/#">LS</a>    
  44.  
  45.     <a href="http://lubcdc.blog.51cto.com/#" class="blue">DNS</a>    
  46.  
  47.     <a href="http://lubcdc.blog.51cto.com/#">FTP</a>    
  48.  
  49.     <a href="http://lubcdc.blog.51cto.com/#">51CTO</a>    
  50.  
  51.     <a href="http://lubcdc.blog.51cto.com/#" class="blue">OOP</a>    
  52.  
  53.     <a href="http://lubcdc.blog.51cto.com/#">XHTML</a>    
  54.  
  55.     <a href="http://lubcdc.blog.51cto.com/#" class="blue">setInterval</a>    
  56.  
  57.     <a href="http://lubcdc.blog.51cto.com/#">W3C</a>    
  58.  
  59.     <a href="http://lubcdc.blog.51cto.com/#">HP-UX</a> 
  60.       
  61.     <a href="http://lubcdc.blog.51cto.com/#">新聞</a> 
  62.       
  63.     <a href="http://lubcdc.blog.51cto.com/#">SUN</a> 
  64.  
  65.     <a href="http://lubcdc.blog.51cto.com/#" class="yellow">法律</a>    
  66.  
  67.     <a href="http://lubcdc.blog.51cto.com/#">愛情</a>    
  68.  
  69. </div>    
  70.  
  71. <p>盡在博客<a href="http://lubcdc.blog.51cto.com/#">http://lubcdc.blog.51cto.com/#</a></p>    
  72.  
  73. </body>    
  74.  
  75. </html>  

mycloud.js

 

  1. var radius = 120;    
  2.  
  3. var dtr = Math.PI/180;    
  4.  
  5. var d=300;    
  6.  
  7.      
  8.  
  9. var mcList = [];    
  10.  
  11. var active = false;    
  12.  
  13. var lasta = 1;    
  14.  
  15. var lastb = 1;    
  16.  
  17. var distr = true;    
  18.  
  19. var tspeed=10;    
  20.  
  21. var size=250;    
  22.  
  23.      
  24.  
  25. var mouseX=0;    
  26.  
  27. var mouseY=0;    
  28.  
  29.      
  30.  
  31. var howElliptical=1;    
  32.  
  33.      
  34.  
  35. var aA=null;    
  36.  
  37. var oDiv=null;    
  38.  
  39.      
  40.  
  41. window.onload=function ()    
  42.  
  43. {    
  44.  
  45.     var i=0;    
  46.  
  47.     var oTag=null;    
  48.  
  49.          
  50.  
  51.     oDiv=document.getElementById('div1');    
  52.  
  53.          
  54.  
  55.     aA=oDiv.getElementsByTagName('a');    
  56.  
  57.          
  58.  
  59.     for(i=0;i<aA.length;i++)    
  60.  
  61.     {    
  62.  
  63.         oTag={};    
  64.  
  65.              
  66.  
  67.         oTag.offsetWidth=aA[i].offsetWidth;    
  68.  
  69.         oTag.offsetHeight=aA[i].offsetHeight;    
  70.  
  71.              
  72.  
  73.         mcList.push(oTag);    
  74.  
  75.     }    
  76.  
  77.          
  78.  
  79.     sineCosine( 0,0,0 );    
  80.  
  81.          
  82.  
  83.     positionAll();    
  84.  
  85.          
  86.  
  87.     oDiv.onmouseover=function ()    
  88.  
  89.     {    
  90.  
  91.         active=true;    
  92.  
  93.     };    
  94.  
  95.          
  96.  
  97.     oDiv.onmouseout=function ()    
  98.  
  99.     {    
  100.  
  101.         active=false;    
  102.  
  103.     };    
  104.  
  105.          
  106.  
  107.     oDiv.onmousemove=function (ev)    
  108.  
  109.     {    
  110.  
  111.         var oEvent=window.event || ev;    
  112.  
  113.              
  114.  
  115.         mouseX=oEvent.clientX-(oDiv.offsetLeft+oDiv.offsetWidth/2);    
  116.  
  117.         mouseY=oEvent.clientY-(oDiv.offsetTop+oDiv.offsetHeight/2);    
  118.  
  119.              
  120.  
  121.         mouseX/=5;    
  122.  
  123.         mouseY/=5;    
  124.  
  125.     };    
  126.  
  127.          
  128.  
  129.     setInterval(update, 30);    
  130.  
  131. };    
  132.  
  133.      
  134.  
  135. function update()    
  136.  
  137. {    
  138.  
  139.     var a;    
  140.  
  141.     var b;    
  142.  
  143.          
  144.  
  145.     if(active)    
  146.  
  147.     {    
  148.  
  149.         a = (-Math.min( Math.max( -mouseY, -size ), size ) / radius ) * tspeed;    
  150.  
  151.         b = (Math.min( Math.max( -mouseX, -size ), size ) / radius ) * tspeed;    
  152.  
  153.     }    
  154.  
  155.     else   
  156.  
  157.     {    
  158.  
  159.         a = lasta * 0.98;    
  160.  
  161.         b = lastb * 0.98;    
  162.  
  163.     }    
  164.  
  165.          
  166.  
  167.     lasta=a;    
  168.  
  169.     lastb=b;    
  170.  
  171.          
  172.  
  173.     if(Math.abs(a)<=0.01 && Math.abs(b)<=0.01)    
  174.  
  175.     {    
  176.  
  177.         return;    
  178.  
  179.     }    
  180.  
  181.          
  182.  
  183.     var c=0;    
  184.  
  185.     sineCosine(a,b,c);    
  186.  
  187.     for(var j=0;j<mcList.length;j++)    
  188.  
  189.     {    
  190.  
  191.         var rx1=mcList[j].cx;    
  192.  
  193.         var ry1=mcList[j].cy*ca+mcList[j].cz*(-sa);    
  194.  
  195.         var rz1=mcList[j].cy*sa+mcList[j].cz*ca;    
  196.  
  197.              
  198.  
  199.         var rx2=rx1*cb+rz1*sb;    
  200.  
  201.         var ry2=ry1;    
  202.  
  203.         var rz2=rx1*(-sb)+rz1*cb;    
  204.  
  205.              
  206.  
  207.         var rx3=rx2*cc+ry2*(-sc);    
  208.  
  209.         var ry3=rx2*sc+ry2*cc;    
  210.  
  211.         var rz3=rz2;    
  212.  
  213.              
  214.  
  215.         mcList[j].cx=rx3;    
  216.  
  217.         mcList[j].cy=ry3;    
  218.  
  219.         mcList[j].cz=rz3;    
  220.  
  221.              
  222.  
  223.         per=d/(d+rz3);    
  224.  
  225.              
  226.  
  227.         mcList[j].x=(howElliptical*rx3*per)-(howElliptical*2);    
  228.  
  229.         mcList[j].y=ry3*per;    
  230.  
  231.         mcList[j].scale=per;    
  232.  
  233.         mcList[j].alpha=per;    
  234.  
  235.              
  236.  
  237.         mcList[j].alpha=(mcList[j].alpha-0.6)*(10/6);    
  238.  
  239.     }    
  240.  
  241.          
  242.  
  243.     doPosition();    
  244.  
  245.     depthSort();    
  246.  
  247. }    
  248.  
  249.      
  250.  
  251. function depthSort()    
  252.  
  253. {    
  254.  
  255.     var i=0;    
  256.  
  257.     var aTmp=[];    
  258.  
  259.          
  260.  
  261.     for(i=0;i<aA.length;i++)    
  262.  
  263.     {    
  264.  
  265.         aTmp.push(aA[i]);    
  266.  
  267.     }    
  268.  
  269.          
  270.  
  271.     aTmp.sort    
  272.  
  273.     (    
  274.  
  275.         function (vItem1, vItem2)    
  276.  
  277.         {    
  278.  
  279.             if(vItem1.cz>vItem2.cz)    
  280.  
  281.             {    
  282.  
  283.                 return -1;    
  284.  
  285.             }    
  286.  
  287.             else if(vItem1.cz<vItem2.cz)    
  288.  
  289.             {    
  290.  
  291.                 return 1;    
  292.  
  293.             }    
  294.  
  295.             else   
  296.  
  297.             {    
  298.  
  299.                 return 0;    
  300.  
  301.             }    
  302.  
  303.         }    
  304.  
  305.     );    
  306.  
  307.          
  308.  
  309.     for(i=0;i<aTmp.length;i++)    
  310.  
  311.     {    
  312.  
  313.         aTmp[i].style.zIndex=i;    
  314.  
  315.     }    
  316.  
  317. }    
  318.  
  319.      
  320.  
  321. function positionAll()    
  322.  
  323. {    
  324.  
  325.     var phi=0;    
  326.  
  327.     var theta=0;    
  328.  
  329.     var max=mcList.length;    
  330.  
  331.     var i=0;    
  332.  
  333.          
  334.  
  335.     var aTmp=[];    
  336.  
  337.     var oFragment=document.createDocumentFragment();    
  338.  
  339.          
  340.  
  341.     //???????    
  342.  
  343.     for(i=0;i<aA.length;i++)    
  344.  
  345.     {    
  346.  
  347.         aTmp.push(aA[i]);    
  348.  
  349.     }    
  350.  
  351.          
  352.  
  353.     aTmp.sort    
  354.  
  355.     (    
  356.  
  357.         function ()    
  358.  
  359.         {    
  360.  
  361.             return Math.random()<0.5?1:-1;    
  362.  
  363.         }    
  364.  
  365.     );    
  366.  
  367.          
  368.  
  369.     for(i=0;i<aTmp.length;i++)    
  370.  
  371.     {    
  372.  
  373.         oFragment.appendChild(aTmp[i]);    
  374.  
  375.     }    
  376.  
  377.          
  378.  
  379.     oDiv.appendChild(oFragment);    
  380.  
  381.          
  382.  
  383.     for( var i=1; i<max+1; i++){    
  384.  
  385.         if( distr )    
  386.  
  387.         {    
  388.  
  389.             phi = Math.acos(-1+(2*i-1)/max);    
  390.  
  391.             theta = Math.sqrt(max*Math.PI)*phi;    
  392.  
  393.         }    
  394.  
  395.         else   
  396.  
  397.         {    
  398.  
  399.             phi = Math.random()*(Math.PI);    
  400.  
  401.             theta = Math.random()*(2*Math.PI);    
  402.  
  403.         }    
  404.  
  405.         //???任    
  406.  
  407.         mcList[i-1].cx = radius * Math.cos(theta)*Math.sin(phi);    
  408.  
  409.         mcList[i-1].cy = radius * Math.sin(theta)*Math.sin(phi);    
  410.  
  411.         mcList[i-1].cz = radius * Math.cos(phi);    
  412.  
  413.              
  414.  
  415.         aA[i-1].style.left=mcList[i-1].cx+oDiv.offsetWidth/2-mcList[i-1].offsetWidth/2+'px';    
  416.  
  417.         aA[i-1].style.top=mcList[i-1].cy+oDiv.offsetHeight/2-mcList[i-1].offsetHeight/2+'px';    
  418.  
  419.     }    
  420.  
  421. }    
  422.  
  423.      
  424.  
  425. function doPosition()    
  426.  
  427. {    
  428.  
  429.     var l=oDiv.offsetWidth/2;    
  430.  
  431.     var t=oDiv.offsetHeight/2;    
  432.  
  433.     for(var i=0;i<mcList.length;i++)    
  434.  
  435.     {    
  436.  
  437.         aA[i].style.left=mcList[i].cx+l-mcList[i].offsetWidth/2+'px';    
  438.  
  439.         aA[i].style.top=mcList[i].cy+t-mcList[i].offsetHeight/2+'px';    
  440.  
  441.              
  442.  
  443.         aA[i].style.fontSize=Math.ceil(12*mcList[i].scale/2)+8+'px';    
  444.  
  445.              
  446.  
  447.         aA[i].style.filter="alpha(opacity="+100*mcList[i].alpha+")";    
  448.  
  449.         aA[i].style.opacity=mcList[i].alpha;    
  450.  
  451.     }    
  452.  
  453. }    
  454.  
  455.      
  456.  
  457. function sineCosine( a, b, c)    
  458.  
  459. {    
  460.  
  461.     sa = Math.sin(a * dtr);    
  462.  
  463.     ca = Math.cos(a * dtr);    
  464.  
  465.     sb = Math.sin(b * dtr);    
  466.  
  467.     cb = Math.cos(b * dtr);    
  468.  
  469.     sc = Math.sin(c * dtr);    
  470.  
  471.     cc = Math.cos(c * dtr);    
  472.  
  473. }  

mystyle.css

 

  1. body {background: #000 url(index.png) no-repeat center 230px;}    
  2.  
  3. #div1 {position:relative; width:450px; height:450px; margin: 20px auto 0; }    
  4.  
  5. #div1 a {position:absolute; top:0px; left:0px; font-family: Microsoft YaHei; color:#fff; font-weight:bold; text-decoration:none; padding: 3px 6px; }    
  6.  
  7. #div1 a:hover {border: 1px solid #eee; background: #000; }    
  8.  
  9. #div1 .blue {color:blue;}    
  10.  
  11. #div1 .red {color:red;}    
  12.  
  13. #div1 .yellow {color:yellow;}    
  14.  
  15.      
  16.  
  17. p { font: 16px Microsoft YaHei; text-align: center; color: #ba0c0c; }    
  18.  
  19. p a { font-size: 14px; color: #ba0c0c; }    
  20.  
  21. p a:hover { color: red; }    
  22.  
  23. p a:hover {color:red; }  

效果圖:

 

測試結果

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章