基于jquery實(shí)現(xiàn)動(dòng)態(tài)豎向柱狀條特效
本文實(shí)例介紹了jquery實(shí)現(xiàn)的柱狀條,常用于數(shù)據(jù)統(tǒng)計(jì),下面就對(duì)代碼做一下分享,并詳細(xì)介紹一下它的實(shí)現(xiàn)過程。
代碼如下:
<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>
上面的代碼實(shí)現(xiàn)柱狀條數(shù)據(jù)的動(dòng)態(tài)效果,下面介紹一下它的實(shí)現(xiàn)過程。
1.$(function(){}),當(dāng)文檔結(jié)構(gòu)完全加載完畢災(zāi)區(qū)執(zhí)行函數(shù)中的代碼。
2.var i=1,聲明一個(gè)變量并賦初值為1,在后面會(huì)用到,這里暫時(shí)不做介紹。
3.$('#top').height(8),設(shè)置top元素的高度為8px。
4.$('#buttom').css('marginTop',42),設(shè)置buttom元素的上邊距為42px42+8=50恰好是容器元素的高度,這樣top元素就能夠恰好位于容器的頂端。
5.$('#buttom').css('background','#d6d6d6'),設(shè)置bottom元素的背景顏色。
6.interid=setInterval(Showgao,0),使用定時(shí)器函數(shù)不斷調(diào)用Showgao函數(shù)。
7.function Showgao(){},此函數(shù)沒執(zhí)行一次,都會(huì)相應(yīng)的設(shè)置一次bottom元素的上外邊距和高度,從而達(dá)到,top元素始終位于頂部和柱狀條動(dòng)態(tài)增加的效果。
8.var oldH=$('#buttom').css('marginTop'),獲取buttom元素的上外邊距的尺寸。9.var h= oldH.substr(0,oldH.indexOf('px')),獲取尺寸值的數(shù)字部分,比如"28px"中的28。
10.$('#buttom').css('marginTop',h-1),將上外邊距的尺寸減一。
11.$('#buttom').height(i),設(shè)置buttom元素的高度。
12.i++,i的值加1。
13.if(i==43){clearInterval(interid);},如果i的值等于43,說明buttom的高度值等于42px,恰好和top的高度和為50px,那么就停止定時(shí)器函數(shù)的執(zhí)行。
以上就是本文的詳細(xì)內(nèi)容,希望對(duì)大家學(xué)習(xí)jquery程序設(shè)計(jì)有所幫助。
相關(guān)文章
jquery讀取xml文件實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法
這篇文章主要介紹了jquery讀取xml文件實(shí)現(xiàn)省市縣三級(jí)聯(lián)動(dòng)的方法,涉及jQuery操作XML文件及Ajax動(dòng)態(tài)加載的技巧,需要的朋友可以參考下2015-05-05
jQuery+Ajax請(qǐng)求本地?cái)?shù)據(jù)加載商品列表頁并跳轉(zhuǎn)詳情頁的實(shí)現(xiàn)方法
本文通過實(shí)例代碼給大家介紹了jQuery+Ajax請(qǐng)求本地?cái)?shù)據(jù)加載商品列表頁并跳轉(zhuǎn)詳情頁,需要的朋友可以參考下2017-07-07
jQuery實(shí)現(xiàn)給input綁定回車事件的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)給input綁定回車事件的方法,結(jié)合實(shí)例形式分析了2種常用的事件綁定操作技巧,需要的朋友可以參考下2017-02-02
jQuery基于ID調(diào)用指定iframe頁面內(nèi)的方法
這篇文章主要介紹了jQuery基于ID調(diào)用指定iframe頁面內(nèi)的方法,涉及jQuery針對(duì)頁面框架元素的選擇與方法的調(diào)用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
jQuery實(shí)現(xiàn)在下拉列表選擇時(shí)獲取json數(shù)據(jù)的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)在下拉列表選擇時(shí)獲取json數(shù)據(jù)的方法,主要涉及jQuery中g(shù)etJSON方法的使用技巧,需要的朋友可以參考下2015-04-04
jquery實(shí)現(xiàn)用戶登陸界面(示例講解)
下面小編就為大家?guī)硪黄猨query實(shí)現(xiàn)用戶登陸界面(示例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-09-09

