![](/img/trans.png)
[英]How can I make this HTML5 canvas progress bar fill from the bottom up instead of the top down?
[英]Progress Bar Fill Up Bottom-To-Top
所以,我有一個進度欄。 使用簡單的顏色,它可以完美工作。 當我放入圖像時,它從上到下而不是從下到上填充,而且我不知道如何解決。 救命?
http://jsfiddle.net/Aiphira/1k8sddvq/
<div id="load-form">
<div class="load-line"></div>
</div>
<center>
<div class="percent"></div>
<div class="asd">2000</div>
</center>
$(document).ready(function(e) {
var maxonline = 6000;
var currentonline = $(this).find('.asd').html();
var percent = currentonline/maxonline*100;
if(percent > 100)
percent = 100;
if(currentonline > maxonline) {
alert('Its full');
return;
}
$('.load-line').animate({height: percent+'%' },500);
$('.percent').html(percent+'%')
});
#load-form { width:137px; height:87px; background:url('http://la2portal.us.lt/status_online_simple.png'); margin:100px auto 0; position:relative; }
#load-form .load-line { background:url('http://la2portal.us.lt/status_online_full.png'); height:0; width:137px; bottom:4px; left:6px; max-height:87px;}
選項1:
.load-form, .load-line{
vertical-align:bottom
}
選項2:
.load-line{
position:absolute;
bottom:0;
}
做這種事情需要絕對定位和背景定位。 添加這些
#load-form .load-line {
position: absolute;
background: url('http://la2portal.us.lt/status_online_full.png') no-repeat bottom;
$(document).ready(function(e) { var maxonline = 6000; var currentonline = $(this).find('.asd').html(); var percent = currentonline/maxonline*100; if(percent > 100) percent = 100; if(currentonline > maxonline) { alert('Its full'); return; } $('.load-line').animate({height: percent+'%' },500); $('.percent').html(percent+'%') });
#load-form { width: 137px; height: 87px; background: url('http://la2portal.us.lt/status_online_simple.png'); margin: 100px auto 0px; position: relative; } #load-form .load-line { position: absolute; background: url('http://la2portal.us.lt/status_online_full.png') no-repeat bottom; height: 0px; width: 137px; bottom: 0px; max-height: 87px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="load-form"> <div class="load-line"></div> </div> <center> <div class="percent"></div> <div class="asd">2000</div> </center>
正如其他人指出的那樣,不贊成使用center
,不建議使用它。 (必須將其包括給可能在這里沒有看評論的人。)
我嘗試通過在頂部添加另一個灰色層並使其尺寸縮小的粗略方法。 這有助於創建綠色層實際上是從底部填充的錯覺。 看一看! http://jsfiddle.net/Lgnk5mnz/2/
在div Cover類中添加HTML:
<div id="load-form">
<div class="load-line"></div>
<div class="cover"></div>
</div>
<center>
<div class="percent"></div>
<div class="asd">2000</div>
</center>
CSS為封面類添加CSS:
#load-form {
width:137px;
height:87px;
background:url('http://la2portal.us.lt/status_online_simple.png');
margin:100px auto 0;
position:relative;
}
#load-form .load-line {
background:url('http://la2portal.us.lt/status_online_full.png');
height:87px;
width:137px;
bottom:4px;
left:6px;
max-height:87px;
}
#load-form .cover {
width:137px;
height:87px;
background:url('http://la2portal.us.lt/status_online_simple.png');
margin:-87px auto 0;
position:relative;
}
最后,為Cover類設置動畫,並刪除加載線的動畫。 $(document).ready(function(e){
var maxonline = 6000;
var currentonline = $(this).find('.asd').html();
var percent = currentonline / maxonline * 100;
if (percent > 100) percent = 100;
if (currentonline > maxonline) {
alert('Its full');
return;
}
$('.cover').animate({
height: 100 - percent + '%'
}, 500);
$('.percent').html(percent + '%')
});
在這里,您可以訪問http://jsfiddle.net/5x275eh1/ 。 我只改變了你的CSS
#load-form { width:137px; height:87px; background:url('http://la2portal.us.lt/status_online_simple.png'); margin:100px auto 0; position:relative; bottom:4px; left:6px;}
#load-form .load-line { background:url('http://la2portal.us.lt/status_online_full.png'); height:0; width:137px; max-height:87px;}
.load-line {
transform: rotateX(180deg);
position:absolute;
bottom:0px; left:0px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.