[英]how do I create bootstrap progress bar using vanilla JS and if not vanilla than something
有此代码
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
<div class="progress-bar bg-success" role="progressbar" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
progressBarElemdiv class="progress-bar bg-info" role="progressbar" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
</div>
从这里https://getbootstrap.com/docs/4.3/components/progress/
我只想使用js创建相同的progressBar
我开始
progressBarElem = document.createElement("div");
progressBarElem.className = "progress-bar"
progressBarElem.setAttribute("role","progressbar")
progressBarElem.setAttribute("aria-valuenow",70)
progressBarElem.style.width = 50 + '%';
progressBarElem.setAttribute("aria-valuemin",0)
progressBarElem.setAttribute("aria-valuemax",100)
progressBarElem.setAttribute("aria-valuemax",100)
progressBarElem.style.width = 200
progressBarElem.style.height = 50
progressBarElem.textContent = "Sss"
document.querySelector(".body").appendChild(progressBarElem)
console.log(progressBarElem);
但是我仍然需要设置很多属性,并且需要一些transion,它变得非常混乱,有没有更快的方法?
可能是这个吗?
= HTML =
<div id="Hidden-Elements" style="display: none">
<div class="progress-bar" role="progressbar" style="width: 50%"
aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
</div>
= JS =
const progressBarElem = document.querySelector('#Hidden-Elements div.progress-bar').cloneNode(true)
document.querySelector(".body").appendChild(progressBarElem)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.