简体   繁体   English

带有垂直线的进度条

[英]Progressbar with vertical line

I am implementing a simulation of a Dutch- and an English-auction in otree.我正在 otree 中模拟荷兰和英国拍卖。
For the interface, I am using a progress bar for the price that the supplier gets.对于界面,我使用了供应商获得的价格的进度条。
In the English-auction the price increases every half second and in the Dutch-auction the price decreases every half second.在英式拍卖中,价格每半秒上涨一次,而在荷兰式拍卖中,价格每半秒下降一次。

Now I want to add a vertical line for the costs of the supplier, which changes every round.现在我想为供应商的成本添加一条垂直线,每轮都会发生变化。 How can i add a vertical line to the progress bar?如何在进度条上添加一条垂直线?

 <style> #myProgress { width: 100%; background-color: #ddd; } #myCosts { width: 100%; background-color: #ddd; } #myBar { width: 100%; height: 30px; background-color: #40bf80; text-align: center; line-height: 30px; color: white; } #costLine{ width: 0%; height: 30px; background-color: #FF0000; text-align: center; line-height: 30px; color: white; } .bg-info{ background-color: #ddd; } </style> Your costs for this round are: <div id="myCosts"> <div id="costLine">{{player.cost}}</div> </div> Current price is: <div id="myProgress"> <div id="myBar">$200</div> </div> <p></p> <p id="Message"></p> <script> var left_line = ({{player.cost|json}}-101); var right_line = (200-{{player.cost|json}}); let cost = {{player.cost|json}} let bot_stop = {{player.bot_stop|json}}; let price = {{Constants.start_value|json}}; var Auction; var Auction2; document.getElementById("costLine").innerHTML = "$"+cost; document.getElementById("costLine").style.width = cost-100+'%'; function startAuction(){ document.getElementById("stop_button").disabled = false; document.getElementById("start_button").disabled = true; Auction = setInterval(function(){ if(price == bot_stop){ document.getElementById("Message").innerHTML = 'The other supplier has dropped out. You win with a price of ' + bot_stop; document.getElementById("stop_button").innerHTML = 'Next Page' stopAuction(); } if(price != bot_stop){ price = price -1; document.getElementById("myBar").innerHTML='$'+price; document.getElementById("myBar").style.width = (price-100) +'%'; } },500) } function stopAuction() { document.querySelector("[name=winning_price]").value = price; document.getElementById("stop_button").innerHTML = 'Next Page' clearInterval(Auction); } </script> <button type="button" class="otree-btn-next btn btn-primary" id="start_button" onclick="startAuction()">Start Auction</button> <button class="otree-btn-next btn btn-primary" disabled id="stop_button" onclick="stopAuction()">Drop Out</button> <p></p> <p></p> <input type="hidden" name="winning_price" />

在此处输入图片说明

  1. Add a child element <div id=myBarPrice></div> to <div id="myProgress"> .将子元素<div id=myBarPrice></div><div id="myProgress">
  2. Add position: relative;添加position: relative; attribute to the #myProgress selector.属性到#myProgress选择器。
  3. Add new style block for a new element:为新元素添加新样式块:
#myBarPrice {
  background-color: #FF0000;
  width: 2px;
  height: 100%;
  position: absolute;
  right: 100%;
  top: 0;
}
  1. Set #myBarPrice position with js:使用 js 设置#myBarPrice位置:
...
    document.getElementById("costLine").innerHTML = "$"+cost;
    document.getElementById("costLine").style.width = cost-100+'%';
    document.getElementById("myBarPrice").style.right = cost+'%'; // <===== 
    function startAuction(){
        document.getElementById("stop_button").disabled = false;
        document.getElementById("start_button").disabled = true;
...

Here is a mockup in codepen.io这是 codepen.io 中的模型

CSS code: CSS代码:

#myProgress {
  width: 100%;
  background-color: #ddd;
  position: relative;
}
#myCosts {
  width: 100%;
  background-color: #ddd;
}
#myBar {
  width: 80%;
  height: 30px;
  background-color: #40bf80;
  text-align: center;
  line-height: 30px;
  color: white;
}
#myBarPrice {
  background-color: #FF0000;
  width: 2px;
  height: 100%;
  position: absolute;
  right: 40%;
  top: 0;
}
#costLine{
  width: 60%;
  height: 30px;
  background-color: #FF0000;
  text-align: center;
  line-height: 30px;
  color: white;
}
.bg-info{
    background-color: #ddd;
}

HTML code: HTML代码:

Your costs for this round are:
<div id="myCosts">
  <div id="costLine">{{player.cost}}</div>
</div>
Current price is:
<div id="myProgress">
  <div id="myBar">$200</div>
  <div id=myBarPrice></div>
</div>

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

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