使用jQuery制作3d标签云教程

渲染JavaScript的浏览器,比以往更快例如firefox,ie不提了,发挥jQuery 创意。此教程将展示如何创建一个滚动的3d标签云.
我们先来看下css
body{
    font-family: Arial, "MS Trebuchet", sans-serif;
    background-color: #111;
   }
   #list{
    margin:0 auto;
    height:600px;
    width:600px;
    overflow:hidden;
    position:relative;
    background-color: #000;
   }
   #list ul,
   #list li{
    list-style:none;
    margin:0;
    padding:0;
   }
   #list a{
    position:absolute;
    text-decoration: none;
    color:#666;
   }
   #list a:hover{
    color:#ccc;
   }
html代码:
<div id="list">
   <ul>
    <li><a href="#">ajax</a></li>
    <li><a href="#">css</a></li>
    <li><a href="#">design</a></li>
    <li><a href="#">firefox</a></li>
    <li><a href="#">flash</a></li>
    <li><a href="#">html</a></li>
    <li><a href="#">Devirtuoso</a></li>
    <li><a href="#">jquery</a></li>
    <li><a href="#">PHP</a></li>
    <li><a href="#">SEO</a></li>
    <li><a href="#">usability</a></li>
    <li><a href="#">www</a></li>
    <li><a href="#">web</a></li>
    <li><a href="#">xhtml</a></li>
   
   </ul>
  </div>
javascript代码:
$(document).ready(function(){
 
 var element = $('#list a');;
 var offset = 0;
 var stepping = 0.03;
 var list = $('#list');
 var $list = $(list)
 
 $list.mousemove(function(e){
  var topOfList = $list.eq(0).offset().top
  var listHeight = $list.height()
  stepping = (e.clientY - topOfList) /  listHeight * 0.2 - 0.1;
  
 });
 
 for (var i = element.length - 1; i >= 0; i--)
 {
  element[i].elemAngle = i * Math.PI * 2 / element.length;
 }
 
 
 setInterval(render, 20);
 
 
 function render(){
  for (var i = element.length - 1; i >= 0; i--){
   
   var angle = element[i].elemAngle + offset;
   
   x = 120 + Math.sin(angle) * 30;
   y = 45 + Math.cos(angle) * 40;
   size = Math.round(40 - Math.sin(angle) * 40);
   
   var elementCenter = $(element[i]).width() / 2;
 
   var leftValue = (($list.width()/2) * x / 100 - elementCenter) + "px"
 
   $(element[i]).css("fontSize", size + "pt");
   $(element[i]).css("opacity",size/100);
   $(element[i]).css("zIndex" ,size);
   $(element[i]).css("left" ,leftValue);
   $(element[i]).css("top", y + "%");
  }
  
  offset += stepping;
 }
 
 
});
注意还要加上jq库
<script src=" http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>

你可能感兴趣的:(jquery,职场,制作,休闲,云教程)