基于jquery實(shí)現(xiàn)動(dòng)態(tài)豎向柱狀條特效
本文實(shí)例介紹了jquery實(shí)現(xiàn)的柱狀條,常用于數(shù)據(jù)統(tǒng)計(jì),下面就對(duì)代碼做一下分享,并詳細(xì)介紹一下它的實(shí)現(xiàn)過(guò)程。
代碼如下:
<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)過(guò)程。
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ù)沒(méi)執(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,說(shuō)明buttom的高度值等于42px,恰好和top的高度和為50px,那么就停止定時(shí)器函數(shù)的執(zhí)行。
以上就是本文的詳細(xì)內(nèi)容,希望對(duì)大家學(xué)習(xí)jquery程序設(shè)計(jì)有所幫助。
相關(guān)文章
jQuery實(shí)現(xiàn)每隔幾條元素增加1條線的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)每隔幾條元素增加1條線的方法,可實(shí)現(xiàn)每隔10條li元素增加一條虛線的功能,涉及jQuery元素的匹配與屬性動(dòng)態(tài)設(shè)置技巧,需要的朋友可以參考下2016-06-06
在次封裝easyui-Dialog插件實(shí)現(xiàn)代碼
在次封裝easyui-Dialog插件實(shí)現(xiàn)代碼,需要的朋友可以參考下。2010-11-11
JQuery通過(guò)后臺(tái)獲取數(shù)據(jù)遍歷到前臺(tái)的方法
今天小編就為大家分享一篇JQuery通過(guò)后臺(tái)獲取數(shù)據(jù)遍歷到前臺(tái)的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08
jQuery實(shí)現(xiàn)仿騰訊迷你首頁(yè)選項(xiàng)卡效果代碼
這篇文章主要介紹了jQuery實(shí)現(xiàn)仿騰訊迷你首頁(yè)選項(xiàng)卡效果代碼,可實(shí)現(xiàn)tab切換按鈕的左右滑動(dòng)顯示及點(diǎn)擊切換效果,涉及jQuery基于鼠標(biāo)事件實(shí)現(xiàn)頁(yè)面元素動(dòng)態(tài)操作技巧,需要的朋友可以參考下2015-09-09
jquery仿QQ商城帶左右按鈕控制焦點(diǎn)圖片切換滾動(dòng)效果
jquery圖片特效制作仿騰訊QQ商城首頁(yè)banner焦點(diǎn)圖片輪播切換效果,帶索引按鈕控制和左右按鈕控制圖片切換,實(shí)例代碼如下,感興趣的朋友可以參考下哈2013-06-06
使用PHP+JQuery+Ajax分頁(yè)的實(shí)現(xiàn)
本篇文章小編將為大家介紹,使用PHP+JQuery+Ajax分頁(yè)的實(shí)現(xiàn)。需要的朋友參考下2013-04-04

