【发布时间】:2017-03-27 02:54:35
【问题描述】:
我正在开发一个可以发布金额的简单 jquery 加载栏。我的问题是,即使在 javascript 中设置了 settimeout,它似乎也只能跳转到最后一个结果。
测试脚本包含 3 个可以完美运行的按钮,但是我需要能够从底部的内联代码调用该函数。这似乎会跳到最后一个结果 75%,而没有显示 25% 并等待 3 秒,就像我希望的那样。
<!DOCTYPE html>
<html>
<style>
#Progress {
width: 100%;
background-color: #ddd;
}
#Bar {
width: 1%;
height: 30px;
background-color: #4CAF50;
}
</style>
<body>
<h1>Progress Bar</h1>
<div id="Progress">
<div id="Bar" style="width:0px;"></div>
</div>
<br>
Buttons for testing bar not needed in actual script<br>
<button onclick="move(50)">Test Bar 50%</button> <br>
<button onclick="move(75)">Test Bar 75%</button> <br>
<button onclick="move(100)">Test Bar 100%</button> <br>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script>
function move(amount) {
var elem = document.getElementById("Bar");
elem.style.width = amount + '%';
}
// Inline calls I need to use for my script. These seem to jump to the last one when loaded dispite timeout.
setTimeout(function(){
move(25);
}, 3000);
setTimeout(function(){
move(75);
}, 3000);
</script>
</body>
</html>
【问题讨论】:
标签: javascript jquery progress-bar loading