js彈性運動滑動的菜單

來源:互聯網
上載者:User

標籤:etl   連絡方式   this   doctype   pointer   菜單   mouseover   poi   timer   

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>彈性運動效果下滑的菜單</title>
 <script>
  window.onload = function(){
   var oUl = document.getElementById(‘oul‘);
   var oLi = oul.getElementsByTagName(‘li‘);
   var oLine = document.getElementById(‘#underline‘);
   var oLine= oLi[oLi.length-1]
   for(var i = 0; i < oLi.length-1; i++){
    oLi[i].onmouseover = function(){
     move(oLine,this.offsetLeft);
     console.log(this.offsetLeft)
    }
   }
  }
//封裝好的函數:
  var speed = 0;
  var left = 0;
  function move(obj,target){
   clearInterval(obj.timer);
   obj.timer = setInterval(function(){
    speed += (target - obj.offsetLeft)/5;
    speed *= 0.7;
    left += speed;
    obj.style.left = left + "px";
    if(Math.abs(speed)<1&&Math.abs(target-left)<1){
     obj.style.left = target + "px";
     clearInterval(obj.timer);
    }
    document.title = obj.style.left + ‘|‘ + target;
   }, 30)
  }
 </script>
 <style>
  *{
   margin: 0;
   padding: 0;
  }
  li{
   list-style: none;
   float: left;
   width: 100px;
   height: 30px;
   border: 1px solid #ccc;
   position: relative;
   text-align: center;
   line-height: 30px;
   z-index: 2;
   cursor: pointer;
  }
  #underline{
   width: 101px;
   height: 5px;
   background-color: red;
   position: absolute;
   overflow: hidden;
   border: none;
   top: 26px;
   left: 0;
   z-index: 1;
  }
  ul{
   width: 508px;
   height: 30px;
   position: relative;
   margin: 100px auto 0;
  }
 </style>
</head>
<body>
 <ul id="oul">
  <li>首頁</li>
  <li>關於我們</li>
  <li>產品</li>
  <li>連絡方式</li>
  <li id="underline"></li>
 </ul>
</body>
</html>

js彈性運動滑動的菜單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.