欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

js實現(xiàn)帶緩動動畫的導(dǎo)航欄效果

 更新時間:2017年01月16日 11:12:38   作者:漫步未來  
本篇文章主要分享了js實現(xiàn)帶緩動動畫的導(dǎo)航欄效果的示例代碼。具有一定的參考價值,下面跟著小編一起來看下吧

 話不多說,請看實例代碼:

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="utf-8">
  <style type="text/css">
  ul,li { padding: 0; margin: 0; }
  li { list-style: none; }
   #box{
   height: 48px;
   width: 900px;
   background-color: #459DF5;
   margin: 50px auto;
   position: relative;
   }
   #caution {
   width: 150px;
   height: 48px;
   background-color: #4B92D8;
   position: absolute;
   top: 0;
   left: 0;
   }
 #list {
 position: absolute;
 }
   #list li {
   width: 150px;
   height: 48px;
   float: left;
   color: #fff;
   font: 500 20px/48px "微軟雅黑";
   text-align: center;
   cursor: pointer;
   }
  </style>
  <script type="text/javascript">
   window.onload = function(){
   //獲取ul ID
   var oUl = document.getElementById("list");
   // 獲取span ID
   var caution = document.getElementById("caution");
   //獲取ul 所有孩子
   var aLi = oUl.children;
   //定時器管理
   var timer = null;
   //緩動
   var leader = 0;
   var target = 0;
    //停留
    var current = 0;
   for(var i = 0;i<aLi.length;i++){
     //鼠標(biāo)移動
   aLi[i].onmouseover = function(){
      //關(guān)閉定時器
   clearInterval(timer);
      //獲取當(dāng)前的left值
   target = this.offsetLeft;
      //開啟定時器
   timer = setInterval(autoCaution,20);   
   }
     //鼠標(biāo)點(diǎn)擊
     aLi[i].onmousedown = function(){
      //清楚所有高亮的文字
      for(var j = 0;j<aLi.length;j++){
       aLi[j].style.color = "#fff"; 
      }
      //當(dāng)前點(diǎn)擊欄變?yōu)榧t色
      this.style.color = "#ccc";
      //提示框
      current = this.offsetLeft;
      caution.style.left = current+"px";      
     }
   }
    //鼠標(biāo)離開
   oUl.onmouseout = function(){
     //關(guān)閉定時器
     clearInterval(timer);
     target = current;
     timer = setInterval(autoCaution,20);
   }
   //緩動動畫
   function autoCaution(){   
   leader = leader +(target - leader) /10;
   caution.style.left = leader+"px";
   }
   }
  </script>
 </head>
 <body>
  <div id="box">
  <span id="caution"></span>
  <ul id="list">
  <li>首頁</li>
  <li>公司簡介</li>
  <li>企業(yè)文化</li>
  <li>招賢納士</li>
  <li>企業(yè)論壇</li>
  </ul>
  </div>
 </body>
</html>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論