一個簡單的載入動畫,js實現

來源:互聯網
上載者:User

標籤:==   int   log   div   margin   flow   問題   簡單   間隔   

簡單:

html:

<div class="box">
  <ul>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
  </ul>
</div>

 

css:

.box{
  width: 200px;
  height: 80px;
  margin: 200px auto;
  border: 1px solid red;
}
.box>ul{
  clear: both;
  overflow: hidden;
  margin-left: 20px;
}
.box>ul>li{
  width: 4px;
  height: 40px;
  margin: 20px 5px 0 0px;
  background: skyblue;
  float: left;
  position: relative;
}

 

js:

$(function(){
  big($(".box>ul>li"));
})
  var i=-1;
function big(obj){
  var li_len=obj.length;
  var li_h=obj.height();
  var a_h=li_h+40;
  setInterval(function(){
    i++;
    if(i==li_len){
      i=0;
    }
    obj.eq(i).animate({
      "height":a_h,
      "top":-20+"px"
    },800);
    obj.eq(i-1).animate({
      "height":li_h,
      "top":0
    },800)      
  },200)    
}

動畫執行速度與定時器每次間隔時間自己可以按需求修改。如果兩個的速度不一樣的話,反正測試的時候,噹噹前瀏覽器頁面最小化,然後再最大化時動畫就會有問題,搞不清楚原因

一個簡單的載入動畫,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.