javascript - 如何从下到上显示垂直进度条

标签 javascript html css

我需要帮助 我如何在 window.onload 时制作进度条,它必须从下到上填充,在此代码中它反向工作

function move() {
  var elem = document.getElementById("myBar");   
  var height = 0;
  var id = setInterval(frame, 100);
  function frame() {
    if (height >= 70) {
      clearInterval(id);
    } else {
      height++; 
      elem.style.height = height + '%'; 
      elem.innerHTML = height * 1  + '%';
    }
  }
}
window.onload = move();
#myProgress {
  width:100px;
  background-color: red;
  height:100px
}

#myBar {
  width: 100px;
  background-color: #4CAF50;
  text-align: center;
  color: white;
}
<div id="myProgress">
  <div id="myBar">0</div>
</div>

最佳答案

一个简单的 CSS 方式如下。

function move() {
  var elem = document.getElementById("myBar");   
  var height = 0;
  var id = setInterval(frame, 100);
  function frame() {
    if (height >= 70) {
      clearInterval(id);
    } else {
      height++; 
      elem.style.height = height + '%'; 
      elem.innerHTML = height * 1  + '%';
    }
  }
}
window.onload = move();
#myProgress {
  width:100px;
  background-color: red;
  height:100px;
  position:relative;
}

#myBar {
  width: 100px;
  height: 0px;
  background-color: #4CAF50;
  text-align: center;
  color: white;
  position:absolute;
  bottom:0px;
}
<div id="myProgress">
  <div id="myBar">0</div>
</div>

希望对您有所帮助。如果您希望始终显示号码,请务必询问。但在我看来,这样会更好。

关于javascript - 如何从下到上显示垂直进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46422493/

相关文章:

html - 如何防止ckeditor不添加空白html标签

css multiple classes - 适当的分隔符

javascript - JS : Call certain function before calling each of other functions in file

javascript - jquery/jscript 防止打开多个弹出窗口

ios - 如何将 URL 文件 'Smooth streaming' 转换为 Apple HLs 格式?

css - 显示 :none not working. 尝试了建议的解决方案但没有成功

html - 淡入淡出的文本变成超链接?

javascript - 将音频数据 uri 字符串转换为文件

javascript - 调用特定函数时加载响应数据失败

javascript - 使用 JavaScript 增加元素位置的问题