1. 程式人生 > >動畫統計圖

動畫統計圖

back ransac ack parse ali pad nsa val 動畫

幫朋友做了個小功能,順便分享下。

這是一個統計圖,頁面加載的時候帶有動畫效果。

效果圖:

技術分享圖片

html:

<div class="transaction-amount">
    <div class="transaction-amount-con typePage">
        <div class="columnar" id="investAgain">
            <div id="columnar-item-1" class="columnar-item  columnar-item-1">
                <
span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-01</em></span> </div> <div id="columnar-item-2"
class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-02</em></span
> </div> <div id="columnar-item-3" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-03</em></span> </div> <div id="columnar-item-4" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-04</em></span> </div> <div id="columnar-item-5" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-05</em></span> </div> <div id="columnar-item-6" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-06</em></span> </div> <div id="columnar-item-7" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-07</em></span> </div> <div id="columnar-item-8" class="columnar-item columnar-item-1"> <span class="columnar-color clearfix"> <i class="columnar-value"></i> </span> <span class="columnar-label"><em class="columnar-time">2016-08</em></span> </div> </div> </div>

css:

@charset "utf-8";

.transaction-amount-con,.repayment-amount-con{height:620px;background:#fff;margin-top:30px;}
.repayment-amount-con{margin-bottom:30px;}

.columnar{  padding-left: 10px; position: relative; width:994px;height: 400px; margin:40px auto;}
.columnar-item{ position: relative; float:left; margin-right:20px; width: 63px; height: 100%; }
.columnar-label{ display: block; position: absolute; bottom:-15px; left:-10px; width: 84px; height: 14px; font-size:12px; border:1px solid #000;border-right:none;border-bottom:none;text-align: center; color: #474e5d; }
.columnar-time{display: block;padding-top:18px;}
.columnar-color{background: #9bc5ec; position: absolute; bottom:0; width: 63px; *width: 62px; height: 4%; transition: all 0.4s ease-in-out 0.2s;  }
.columnar-value{ width:58px;height:53px;position: absolute; top: -60px; left:2px; font-size: 14px; line-height:44px;text-align: center;}

.clearfix:before,.clearfix:after{content:"";display:table}
.clearfix:after{clear:both}
.clearfix{*zoom:1}

需要自行先引入jq庫。

js:

var els = $(‘.transaction-amount .columnar-color‘) ;
            increase(els);        
            function increase(obj){
                //console.log(obj)
                var data = [
                            {‘money‘:1600},
                            {‘money‘:500},
                            {‘money‘:120},
                            {‘money‘:200},
                            {‘money‘:300},
                            {‘money‘:11000},
                            {‘money‘:5000},
                            {‘money‘:20}
                        ]
                var maxNum = 0;
                for(var i in data){
                    maxNum += parseFloat(data[i].money);;
                } 
                for(var i in data){
                    var money = parseFloat(data[i].money);
                    var objChild = $(obj[i]).find(".columnar-value");
                    objChild.html(money);
                    var present = money/maxNum;
                    if(present<0.01){
                        present = 0.01;
                    }
                    //console.log(maxNum)
                    $(obj[i]).css({"height":present*100+"%"});
                }   
            }

動畫統計圖