简体   繁体   English

CSS进度条

[英]css progress bar

I have a question in regards to a progress bar. 我对进度条有疑问。 I've read pretty much all the posts here but it appears I can't make any of them work in my scenario. 我在这里阅读了几乎所有文章,但看来我无法在我的情况下使用其中的任何文章。 I have the following which shows numbers such as 50/500 where 50 is the actual number and 500 is the max. 我有以下显示数字,例如50/500,其中50是实际数字,而500是最大数字。

$SQL = "SELECT * FROM db_ships WHERE ship_id = $user[ship_id] LIMIT 1";
$result = mysql_query($SQL);

while ($db_field = mysql_fetch_assoc($result)) {
print $db_field['shields'] . " / ";
print $db_field['max_shields'] . "";

Most progress bars that I see depict timeframes, I need to visually show the fraction 我看到的大多数进度条都描绘了时间范围,我需要直观地显示分数

print $db_field['shields'] . " / ";
    print $db_field['max_shields'] . "";

How can I place this so I can have a progress bar depicting the progress? 我该如何放置它,以便有一个进度条来描述进度? I am sorry I am not good at css. 对不起,我不擅长CSS。 Any help would be greatly appreciated. 任何帮助将不胜感激。

One simple way of doing it is placing a div inside a larger div and setting the percentage width of the inner div. 一种简单的实现方法是将div放在较大的div内并设置内部div的百分比宽度。 Here's a fiddle showing what I mean. 这是一个小提琴,显示了我的意思。

You can get the percentage of max_shields by writing (Assuming they are both numbers) 您可以通过写入获得max_shields的百分比(假设它们都是数字)

$percentage = $db_field['shields'] * ($db_field['max_shields'] / 100);

Apply the percentage as the width of the inner div. 应用百分比作为内部div的宽度。

<div id="progress-inner" style="width: <?php echo $percentage; ?>%;"></div>

It would be a breeze to animate that progress bar using jQuery animate if you wanted to. 如果需要的话,使用jQuery animate对进度条进行动画处理将很容易。

<style type="text/css">
.table, th
{
background-color:Blue;
border-collapse:collapse;
}
<table class="table" >
        <tr id = "row1" >
            <td id ="cell1" class="td"></td>
        </tr>
    </table>    
  <script language="javascript" type="text/javascript" >

    var i = 1;
    var timerID = 0;
    timerID = setTimeout("progress()",200); 
    var scell = '';
    var sbase = '';
    sbase = document.getElementById("cell1").innerHTML;

function progress()
{

    var tend = "</tr></table>";
    var tstrt = "<table><tr>";
    scell = scell + "<td style='width:15;height:25' bgcolor=blue>";

    document.getElementById("cell1").innerHTML = sbase + tstrt +  scell + tend; 


     if( i < 50) 
    {                    
        i = i + 1;

        timerID = setTimeout("progress()",200); 
    }
    else
     {
        if(timerID)
        {
   document.getElementById("cell1")
      .innerHTML=document.getElementById("cell1").innerHTML 
      + "</tr></table>";
            clearTimeout(timerID);

        }
     }

  }
     </script>
echo "<div class=\"progressbar_container\"><div class=\"progressbar\" style=\"width: ".($db_field['shields']/$db_field['max_shields']*100)."%\"></div></div>";

And define styles as needed. 并根据需要定义样式。 Maybe a border for the container and a background colour for the main bar. 可能是容器的边框和主栏的背景色。 That's all there is to a basic progress bar. 这就是基本进度条的全部内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM