英文:
How to add svg end of a progress bar manipuleted by javascript
问题
I am coding a progress bar, and this progress is increasing or decreasing according to the degree from JavaScript. It's okay if the progress bar doesn't work, but I want to add a triangle SVG to the end of this bar and make it arrow-shaped.
The progress bar I made looks like this:
我的实现
but I want it to look like this:
我想要制作的样子
The HTML structure of the progress bar is as follows:
<div class="progress-container">
<div class="progress__fill"></div>
</div>
Here is the progress bar JavaScript code:
<script>
function updateProgressBar(progressBar) {
progressBar.querySelector(".progress__fill").style.width = VALUE;
}
const myProgressBar = document.querySelector(".progress-container");
updateProgressBar(myProgressBar);
</script>
As you can see, it changes according to the progress bar value variable, so I didn't know how to add the SVG in the form of a triangle at the end.
英文:
I am coding a porgress bar and this progress is increasing or decreasing according to the degree from javascript. It's okay if the progress bar doesn't work, but I want to add a triangle svg to the end of this bar and make it arrow shaped.
The progress bar I made looks like this:
my ipmpementation
but I want it to look like this:
how i want to make
The html structure of the progress bar is as follows:
<div class="progress-container">
<div class="progress__fill"></div>
</div>
Here is the progress bar javascript code:
<script >
function updateProgressBar(progressBar) {
progressBar.querySelector(".progress__fill").style.width = VALUE;
}
const myProgressBar = document.querySelector(".progress-container");
updateProgressBar(myProgressBar); </script>
As you can see, it changes according to the progress bar value variable, so I didn't know how to add the svg in the form of triangle at the end.
答案1
得分: 0
为了准确回答您的问题,请检查以下代码片段。现在您可以使用CSS伪类中的三角形来执行相同的操作。
<!-- 开始代码片段: js 隐藏: false 控制台: true Babel: false -->
<!-- 语言: lang-js -->
let VALUE = '50%';
function updateProgressBar(progressBar) {
progressBar.querySelector(".progress__fill").style.width = VALUE;
}
const myProgressBar = document.querySelector(".progress-container");
updateProgressBar(myProgressBar);
<!-- 语言: lang-css -->
.progress-container {
width: 100%;
height: 24px;
background-color: darkgray;
border-radius: 10px;
}
.progress__fill {
float: left;
background-color: red;
width: 25%;
height: 100%;
border-radius: 10px;
}
.progress-container svg {
float: left;
width: 48px;
height: 48px;
margin-top: -12px;
margin-left: -10px;
}
<!-- 语言: lang-html -->
<br>
<div class="progress-container">
<div class="progress__fill"></div>
<svg id="svgTriangle" fill="#ff0000" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
<path d="M 0,48 V 0 l 48,24 z" />
</svg>
</div>
<!-- 结束代码片段 -->
希望这能帮助您解决问题。
英文:
to answer exactly your question, check snippet.
Now you have another way to do that with css triangle in after pseudo class
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
let VALUE = '50%';
function updateProgressBar(progressBar) {
progressBar.querySelector(".progress__fill").style.width = VALUE;
}
const myProgressBar = document.querySelector(".progress-container");
updateProgressBar(myProgressBar);
<!-- language: lang-css -->
.progress-container {
width: 100%;
height: 24px;
background-color: darkgray;
border-radius: 10px;
}
.progress__fill {
float: left;
background-color: red;
width: 25%;
height: 100%;
border-radius: 10px;
}
.progress-container svg {
float: left;
width: 48px;
height: 48px;
margin-top: -12px;
margin-left: -10px;
}
<!-- language: lang-html -->
<br>
<div class="progress-container">
<div class="progress__fill"></div>
<svg id="svgTriangle" fill="#ff0000" viewBox="0 0 48 48" xmlns="http://www.w3.org/2000/svg">
<path d="M 0,48 V 0 l 48,24 z" />
</svg>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论