javascript - how to animate bar chart from bottom to top? - Stack Overflow

I am trying to make a bar chart and the bar animates from top to bottom right now, but I want it to ani

I am trying to make a bar chart and the bar animates from top to bottom right now, but I want it to animate from bottom to top. How do I get it go from bottom to top?

CSS

.bar {
width:50px;
height:250px;
list-style-type:none;
}
.bar p {
background-color:#63F;
}
.bar span { 
padding-left:15px;
left:100%;  
}
#content ul {
list-style-type:none;
}
#content ul li {
float:left;
margin:50px;
}

HTML

<div id="content">
<ul>
  <li>
    <div class="bar">
      <p><span>50%</span></p>
    </div><br>
    Freshmen                    
  </li>
</ul>
</content>

Javascript

<script src="../../jquery-1.6.4.min.js"></script>    
$(document).ready(function(){
    $(".bar").each(function(){
        var length = $(this).find("span").html();
        $(this).find("p").delay(500).animate({'height':length},3500,function(){$(this).find("span").fadeIn(1000);
        });
    });
});

"click here to see it in jsfiddle"

I am trying to make a bar chart and the bar animates from top to bottom right now, but I want it to animate from bottom to top. How do I get it go from bottom to top?

CSS

.bar {
width:50px;
height:250px;
list-style-type:none;
}
.bar p {
background-color:#63F;
}
.bar span { 
padding-left:15px;
left:100%;  
}
#content ul {
list-style-type:none;
}
#content ul li {
float:left;
margin:50px;
}

HTML

<div id="content">
<ul>
  <li>
    <div class="bar">
      <p><span>50%</span></p>
    </div><br>
    Freshmen                    
  </li>
</ul>
</content>

Javascript

<script src="../../jquery-1.6.4.min.js"></script>    
$(document).ready(function(){
    $(".bar").each(function(){
        var length = $(this).find("span").html();
        $(this).find("p").delay(500).animate({'height':length},3500,function(){$(this).find("span").fadeIn(1000);
        });
    });
});

"click here to see it in jsfiddle"

Share Improve this question asked Nov 17, 2012 at 8:21 saolaoanesaolaoane 211 silver badge3 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

You can define position:absolute to your bar. Write like this:

.bar {
width:50px;
height:250px;
list-style-type:none;
    position:relative;
}
.bar p {
background-color:#63F;
    position:absolute;
    bottom:0;
    left:0;
}

Check this http://jsfiddle/6zqSS/1/

http://jsfiddle/t4THf/5/

CSS

.perfect
{
    padding-top:30px;
    width:500px;
    height:300px;
    position:relative;
    background-color:#efefef;
}
.perfect .bar
{
    float:left;
    position:relative;
    width:40px;
    height:100%;
    margin-left:5px;
}
.perfect .bar .slideup
{
    position:absolute;
    bottom:0px;
    width:40px;
    background-color:#fff000;
    border:1px solid #000;
}
.perfect .bar .slideup span
{
    display:block;
    position:absolute;
    margin:5px;
    top:-30px;
}

HTML

<div class="perfect">
    <div class="bar">
        <div class="slideup">
            <span>20%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>30%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>10%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>70%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>100%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>50%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>60%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>55%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>70%</span>
        </div>
    </div>
    <div class="bar">
        <div class="slideup">
            <span>70%</span>
        </div>
    </div>
</div>

JS

$(function(){
     $(".bar").each(function(){
        var length = $(this).find("span").html();
        $(this).find(".slideup").delay(500).animate({'height':length},
"slow",function(){$(this).find("span").fadeIn(1000);
        });
    });
});

Click here for demo

You could also achieve this using css keyframes, for example for webkit http://jsfiddle/kudoslabs/YddaY/

css

dl{ position: relative ; height: 200px ; }
dt,dd{ position: absolute ; }
dd{ height: 70% ; width: 30px ; background: grey ; bottom: 20px ; -webkit-animation: animate-bar 1.25s 1 linear; }
dt{ bottom: 0 ; }
@-webkit-keyframes animate-bar{
    0% {height: 0% ; }
}​

html

<dl>
    <dt>Freshman</dt>    
    <dd>70%</dd>
</dl>​

http://jsfiddle/chovy/6zqSS/2/

.bar {
    position: relative;
}


.bar p {
    position: absolute;
    bottom: 0;
}

Use keyframes to animate the css property, e.g. width Once you set the width of your element (e.g. div) the animation will kick in

.animated-bar {
  animation: animateBar 0.25s ease-in;
  @keyframes animateBar {
    0% {
      width: 0;
    }
  }
}
<div class="animated-bar" style="width: 200px"><div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744142263a4560258.html

相关推荐

  • javascript - how to animate bar chart from bottom to top? - Stack Overflow

    I am trying to make a bar chart and the bar animates from top to bottom right now, but I want it to ani

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信