基於jquery實現動態豎向柱狀條特效,jquery動態豎向

來源:互聯網
上載者:User

基於jquery實現動態豎向柱狀條特效,jquery動態豎向

本文執行個體介紹了jquery實現的柱狀條,常用於資料統計,下面就對代碼做一下分享,並詳細介紹一下它的實現過程。

代碼如下:

<html> <head> <meta charset="gb2312"> <title>jquery柱狀條</title> <style type="text/css">.container{ width:20px; height:50px; border:1px solid #999; font-size:10px; float:left; margin-left:5px;}</style><script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script><script type="text/javascript">$(function(){ var i=1; $('#top').height(8); $('#buttom').css('marginTop',42); $('#buttom').css('background','#d6d6d6');  interid=setInterval(Showgao,0); function Showgao(){  var oldH=$('#buttom').css('marginTop');  var h= oldH.substr(0,oldH.indexOf('px'));  $('#buttom').css('marginTop',h-1);  $('#buttom').height(i);  i++;  if(i==43){clearInterval(interid);} }  var i1=1; $('#top1').height(4); $('#buttom1').css('marginTop',46); $('#buttom1').css('background','red'); interid1=setInterval(Showgao1,1); function Showgao1(){  var oldH=$('#buttom1').css('marginTop');  var h= oldH.substr(0,oldH.indexOf('px'));  $('#buttom1').css('marginTop',h-1);  $('#buttom1').height(i1);  i1++;  if(i1==30){clearInterval(interid1);} }});</script></head><body><div class="container"> <div id="top">82%</div> <div id="buttom"></div></div><div class="container"> <div id="top1" >62%</div> <div id="buttom1"></div></div></body></html>

上面的代碼實現柱狀條資料的動態效果,下面介紹一下它的實現過程。
1.$(function(){}),當文檔結構完全載入完畢災區執行函數中的代碼。
2.var i=1,聲明一個變數並賦初值為1,在後面會用到,這裡暫時不做介紹。

3.$('#top').height(8),設定top元素的高度為8px。
4.$('#buttom').css('marginTop',42),設定buttom元素的上邊距為42px42+8=50恰好是容器元素的高度,這樣top元素就能夠恰好位於容器的頂端。
5.$('#buttom').css('background','#d6d6d6'),設定bottom元素的背景顏色。
6.interid=setInterval(Showgao,0),使用定時器函數不斷調用Showgao函數。
7.function Showgao(){},此函數沒執行一次,都會相應的設定一次bottom元素的上外邊距和高度,從而達到,top元素始終位於頂部和柱狀條動態增加的效果。
8.var oldH=$('#buttom').css('marginTop'),擷取buttom元素的上外邊距的尺寸。9.var h= oldH.substr(0,oldH.indexOf('px')),擷取尺寸值的數字部分,比如"28px"中的28。
10.$('#buttom').css('marginTop',h-1),將上外邊距的尺寸減一。
11.$('#buttom').height(i),設定buttom元素的高度。
12.i++,i的值加1。
13.if(i==43){clearInterval(interid);},如果i的值等於43,說明buttom的高度值等於42px,恰好和top的高度和為50px,那麼就停止定時器函數的執行。

以上就是本文的詳細內容,希望對大家學習jquery程式設計有所協助。

您可能感興趣的文章:
  • JQUBar 基於JQUERY的柱狀圖外掛程式
  • JQUBAR1.1 jQuery 柱狀圖外掛程式發布
  • 使用jQuery jqPlot外掛程式繪製柱狀圖
  • jQuery製作簡單柱狀圖執行個體
  • jQuery.Highcharts.js繪製柱狀圖餅狀圖曲線圖
  • jQuery基於ajax實現帶動畫效果無重新整理柱狀圖投票代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.