简体   繁体   English

需要帮助修改进度条 - html/jquery

[英]Need help modifying progress bar - html/jquery

I have certain tasks/jobs running in the backend.我在后端运行某些任务/作业。 I made a basic webpage which shows in-progress/completion status of those tasks.我制作了一个基本网页,显示这些任务的进行中/完成状态。 My webpage is being refreshed every few seconds and accordingly the new counters of the tasks/jobs completed are displayed.我的网页每隔几秒钟就会刷新一次,因此会显示已完成任务/作业的新计数器。

This Liquid bubble progress bar have caught my attention too much and I want to replicate the same into my basic webpage.这个 Liquid 气泡进度条引起了我太多的注意,我想将其复制到我的基本网页中。 But that one, waits for user to input a number in a text box and accordingly the progress bar changes.但是那个,等待用户在文本框中输入一个数字,因此进度条会发生变化。

I am looking to make it live indicator, ie without manually inputting a value into the text box.我希望使其成为实时指示器,即无需手动将值输入文本框中。

I tried having a function which loads when the page is refreshed and input current completion status counter into that text box (example 22%), but seems there is no effect.我尝试使用一个在页面刷新时加载的函数,并将当前完成状态计数器输入到该文本框(例如 22%)中,但似乎没有效果。

function pbar() {
    document.getElementById("percent-box").value = "22";
}

Reading lines of the actual javascript indicated the bubble changes it value only when there is a keyup - if not it stays at the default value which is set at 67.阅读实际 javascript 的行表明气泡仅在有键时才更改其值 - 如果没有,则保持默认值设置为 67。

Please could I get some help to make the right javascript code and the right function calls to make that a live one.请问我能否得到一些帮助来制作正确的 javascript 代码和正确的函数调用,以使其成为实时代码。 Thanks heaps in advance.提前致谢。

I wrapped the functionality in a setProgressValue function, which you can call at any time.我将该功能封装在一个setProgressValue函数中,您可以随时调用该函数。

Great work by June Hanabi and Jamie Dixon . June HanabiJamie Dixon 的出色工作。

 function setProgressValue(val) { var colorInc = 100 / 3; var valOrig = val; val = 100 - val; if(valOrig == 0) { $("#percent-box").val(0); $(".progress .percent").text(0 + "%"); } else $(".progress .percent").text(valOrig + "%"); $(".progress").parent().removeClass(); $(".progress .water").css("top", val + "%"); if(valOrig < colorInc * 1) $(".progress").parent().addClass("red"); else if(valOrig < colorInc * 2) $(".progress").parent().addClass("orange"); else $(".progress").parent().addClass("green"); } setProgressValue(80) setTimeout(()=>{setProgressValue(42)}, 2000) setTimeout(()=>{setProgressValue(27)}, 4000) setTimeout(()=>{setProgressValue(93)}, 6000) setTimeout(()=>{setProgressValue(67)}, 8000)
 .wrapper > div { transform: scale(.5); } *{box-sizing:border-box}body,html{height:100%}body{background-color:#1a1a1a;font-family:sans-serif;font-size:15px;color:#ccc}.wrapper{display:-webkit-box;display:-ms-flexbox;display:box;display:flex;-webkit-box-align:center;-o-box-align:center;align-items:center;-webkit-box-pack:center;-o-box-pack:center;justify-content:center;-webkit-box-orient:vertical;-o-box-orient:vertical;flex-direction:column;height:100%}.green{margin-top:15px}.green .progress,.orange .progress,.red .progress{position:relative;border-radius:50%}.green .progress,.orange .progress,.red .progress{width:250px;height:250px}.green .progress{border:5px solid #53fc53}.green .progress{box-shadow:0 0 20px #029502}.green .progress,.orange .progress,.red .progress{-webkit-transition:all 1s ease;transition:all 1s ease}.green .progress .inner,.orange .progress .inner,.red .progress .inner{position:absolute;overflow:hidden;z-index:2;border-radius:50%}.green .progress .inner,.orange .progress .inner,.red .progress .inner{width:240px;height:240px}.green .progress .inner,.orange .progress .inner,.red .progress .inner{border:5px solid #1a1a1a}.green .progress .inner,.orange .progress .inner,.red .progress .inner{-webkit-transition:all 1s ease;transition:all 1s ease}.green .progress .inner .water,.orange .progress .inner .water,.red .progress .inner .water{position:absolute;z-index:1;width:200%;height:200%;left:-50%;border-radius:40%;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;-webkit-animation-timing-function:linear;animation-timing-function:linear;-webkit-animation-name:spin;animation-name:spin}.green .progress .inner .water{top:25%}.green .progress .inner .water{background:rgba(83,252,83,.5)}.green .progress .inner .water,.orange .progress .inner .water,.red .progress .inner .water{-webkit-transition:all 1s ease;transition:all 1s ease}.green .progress .inner .water,.orange .progress .inner .water,.red .progress .inner .water{-webkit-animation-duration:10s;animation-duration:10s}.green .progress .inner .water{box-shadow:0 0 20px #03bc03}.green .progress .inner .glare,.orange .progress .inner .glare,.red .progress .inner .glare{position:absolute;top:-120%;left:-120%;z-index:5;width:200%;height:200%;-webkit-transform:rotate(45deg);transform:rotate(45deg);border-radius:50%}.green .progress .inner .glare,.orange .progress .inner .glare,.red .progress .inner .glare{background-color:rgba(255,255,255,.15)}.green .progress .inner .glare,.orange .progress .inner .glare,.red .progress .inner .glare{-webkit-transition:all 1s ease;transition:all 1s ease}.green .progress .inner .percent,.orange .progress .inner .percent,.red .progress .inner .percent{position:absolute;top:0;left:0;width:100%;height:100%;font-weight:700;text-align:center}.green .progress .inner .percent,.orange .progress .inner .percent,.red .progress .inner .percent{line-height:240px;font-size:92.3076923076923px}.green .progress .inner .percent{color:#03c603}.green .progress .inner .percent{text-shadow:0 0 10px #029502}.green .progress .inner .percent,.orange .progress .inner .percent,.red .progress .inner .percent{-webkit-transition:all 1s ease;transition:all 1s ease}.red{margin-top:15px}.red .progress{border:5px solid #ed3b3b}.red .progress{box-shadow:0 0 20px #7a0b0b}.red .progress .inner .water{top:75%}.red .progress .inner .water{background:rgba(237,59,59,.5)}.red .progress .inner .water{box-shadow:0 0 20px #9b0e0e}.red .progress .inner .percent{color:#a30f0f}.red .progress .inner .percent{text-shadow:0 0 10px #7a0b0b}.orange{margin-top:15px}.orange .progress{border:5px solid #f07c3e}.orange .progress{box-shadow:0 0 20px #7e320a}.orange .progress .inner .water{top:50%}.orange .progress .inner .water{background:rgba(240,124,62,.5)}.orange .progress .inner .water{box-shadow:0 0 20px #a0400c}.orange .progress .inner .percent{color:#a8430d}.orange .progress .inner .percent{text-shadow:0 0 10px #7e320a}@-webkit-keyframes spin{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes spin{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="wrapper"> <div class="green"> <div class="progress"> <div class="inner"> <div class="percent"><span>67</span>%</div> <div class="water"></div> <div class="glare"></div> </div> </div> </div> </div>

You may want to consider using a promise.您可能需要考虑使用承诺。 I've included documentation is the example below.我已经包含的文档是下面的例子。 It would avoid refreshing the whole page.它会避免刷新整个页面。

 let promise = new Promise( (resolve, reject) => { // Resolve the promise after 1 second // Replace this with an AJAX call to get the values from the server setTimeout(() => resolve("22"), 1000); }); promise.then( // Change the value with what the promise returned result => { let content = document.getElementById("percent-box"); content.innerHTML = result; }, // In case of an error show an alert error => alert("error") );
 <div id="percent-box">10</div>

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

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