2

我正在尝试制作条形图,并且条形图现在从上到下进行动画处理,但我希望它从下到上进行动画处理。我如何让它从下到上?

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);
        });
    });
});

“单击此处在 jsfiddle 中查看”

4

5 回答 5

3

http://jsfiddle.net/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);
        });
    });
});

点击这里进行演示

于 2013-11-09T09:17:22.653 回答
3

您可以定义position:absolute到您的bar。像这样写:

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

检查这个http://jsfiddle.net/6zqSS/1/

于 2012-11-17T08:26:32.990 回答
1

You could also achieve this using css keyframes, for example for webkit http://jsfiddle.net/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>​
于 2012-11-17T08:59:36.610 回答
0

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

.bar {
    position: relative;
}


.bar p {
    position: absolute;
    bottom: 0;
}
于 2012-11-17T09:49:10.300 回答
0

使用关键帧为 css 属性设置动画,例如宽度 一旦设置了元素的宽度(例如 div),动画就会启动

.animated-bar {
  animation: animateBar 0.25s ease-in;
  @keyframes animateBar {
    0% {
      width: 0;
    }
  }
}
<div class="animated-bar" style="width: 200px"><div>
于 2020-05-29T18:16:37.617 回答