jQuery實現的 “滑動門”(跟隨鼠標滑動滑動的tab選項卡)效果

  1. <!DOCTYPE html PUBLIC  "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >  
  2. <html xmlns="http://www.w3.org/1999/xhtml" >  
  3. <head>  
  4. <meta http-equiv="Content-Type"  content= "text/html; charset=utf-8"  />  
  5. <style>  
  6. ul,li{  
  7.   background-color:#999;  
  8.   margin:0px;  
  9.   padding:0px;  
  10.   list-style:none;  
  11.   color:#fff;  
  12. }  
  13. li{  
  14.   padding:3px;  
  15.   float:left;  
  16.   margin-right:2px;  
  17.   border:#FFF 1px solid;  
  18. }  
  19. div{  
  20.     
  21.   clear:left;  
  22.   height:150px;  
  23.   width:300px;  
  24.   background-color:#666;  
  25.   display:none;  
  26. }  
  27. li.tabin{  
  28.   background-color:#666;  
  29.   border:#666 solid 1px;  
  30. }  
  31. div.contentin{  
  32.     padding:3px;  
  33.     display:block;  
  34.     color:#FFF;  
  35. }  
  36.   
  37. </style>  
  38. <title>jQuery實現常見的滑動門效果</title>  
  39. <script language="javascript"  type= "text/javascript"  src= "../include/jquery-1.5.1.min.js" ></script>  
  40.   
  41. <script type="text/javascript" >  
  42. var  timeoutid;  
  43.   $(function (){  
  44.         
  45.      /*  
  46.      實現滑動門核心  
  47.      1、把當前樣式(li、div選中狀態)移除  
  48.      2、設置鼠標移動到的當前li對象的樣式選中狀態  
  49.      3、設置鼠標移動到的當前li對象所對應的div的樣式選中狀態  
  50.         如何設置當前li對象所對應的div爲選中狀態?  
  51.           
  52.         解決:遍歷所有的li並且根據當前li對象的索引值去設置對應索引值的div  
  53.      */    
  54.    //遍歷所有的li   
  55.     $("li" ).each( function (index){  
  56.      //處理鼠標移動到li上的事件   
  57.      $(this).mouseover(function (){  
  58.            
  59.           var  liObj=$(this);  
  60.           timeoutid=setTimeout(function (){     
  61.           //清空所有的處於選中狀態的樣式   
  62.           $("li.tabin" ).removeClass();  
  63.           $("div.contentin" ).removeClass();  
  64.           //設置當前li索引值對應的div   
  65.           $("div" ).eq(index).addClass( "contentin" );  
  66.            //設置當前的li和當前li所對應的div   
  67.             liObj.addClass("tabin" );  
  68.              
  69.           },300);  
  70.             
  71.       }).mouseout(function (){  
  72.           clearTimeout(timeoutid);  
  73.           });  
  74.        
  75.    });  
  76.  });  
  77. </script>  
  78. </head>  
  79.   
  80. <body>  
  81. jQuery實現常見的滑動門效果  
  82. <hr>  
  83.    <ul>  
  84.     <li class = "tabin" >標籤1</li>  
  85.     <li>標籤2</li>  
  86.     <li>標籤3</li>  
  87.    </ul>  
  88.    <div class = "contentin" >標籤1內容文字</div>  
  89.    <div>標籤2內容文字</div>  
  90.    <div>標籤3內容文字</div>  
  91. </body>  
  92. </html> 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章