灯箱内有2个不同的进度条
lightbox with 2 different progress bar inside
本文关键字:2个 更新时间:2023-09-26
我在javascript中创建了一个灯箱,我在里面放置了一个进度条,我也在javascript中创建了它。我的问题是,当我试图在我的灯箱内插入第二个进度条时,只有第一个工作。知道怎么解决这个问题吗?
这是我的jsfiddle:http://jsfiddle.net/QHMKk/3/
我的代码是这样的:
my javascript is:
function show() {
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block';
}
function start() {
var stepSize = 50;
setTimeout((function() {
var filler = document.getElementById("filler"),
percentage = 0;
return function progress() {
filler.style.height = percentage + "%";
percentage +=1;
if (percentage <= 100) {
setTimeout(progress, stepSize);
}
}
}()), stepSize);
}
function start() {
var stepSize = 50;
setTimeout((function() {
var filler2 = document.getElementById("filler2"),
percentage = 0;
return function progress() {
filler.style.height = percentage + "%";
percentage +=1;
if (percentage <= 100) {
setTimeout(progress, stepSize);
}
}
}()), stepSize);
}
这是我的html:
<a href = "javascript:void(0)" onclick = "show(); start();"> OPEN</a>
<div id="light" class="white_content_stats">
<div class="prog">
<div id="filler" class="filler"></div>
</div>
</br>
<div class="prog2">
<div id="filler2" class="filler2"></div>
</div>
<a href = "javascript:void(0)" onclick = " document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'; ">
</br>CLOSE</a>
这是我的CSS:
.black_overlay_stats{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 50%;
z-index:1001;
-moz-opacity: 0.6;
opacity:.70;
filter: alpha(opacity=70);
}
.white_content_stats {
display: none;
position:fixed;
top: 15%;
width: 300px;
padding: 30px;
margin-left:10px;
background-color:#F2F2F2;
border-radius: 0px;
box-shadow: 0px 0px 0px 20px rgba(0,0,0,0.6);
z-index:1002;
}
.prog {
height: 100px;
width: 30px;
border: 1px solid white;
position: relative;
}
.filler {
height: 0%;
width: 30px;
position: absolute;
bottom: 0;
background-color: grey;
}
.prog2 {
height: 100px;
width: 30px;
border: 1px solid white;
position: relative;
}
.filler2 {
height: 0%;
width: 30px;
position: absolute;
bottom: 0;
background-color: grey;
}
您定义了两个具有相同名称的函数start
,因此将使用第二个函数并且只运行它,因此您可以看到只有一个进度条有效。您可以修改函数start
,使其接受id
的参数,如下所示:
function start(id) {
//...
var filler = document.getElementById(id)
//...
}
然后同时调用start('filler')
和start('filler2')
:
<a href = "javascript:void(0)" onclick = "show(); start('filler'); start('filler2');"> OPEN</a>
更新演示。
注意你不应该使用inline事件属性
相关文章:
- 如何使用url加载程序在webpack中导入多个图像
- 多个单选按钮组相互干扰
- 下拉选择可自动更改第二个下拉选择
- onkeyup无法动态创建多个文本区域
- JQuery合并了keyup和focusout两个函数
- 正在验证8个真/假复选框或复选框中的2个
- 借助asp.net验证或java脚本对多个文本进行验证
- 如何使用 node.js 比较两个 json 数组
- 为复选框javascript指定两个值
- Phonegap-(安卓/iphone)多个图像的图像库出现问题
- jQuery自定义验证比较多个输入的序列
- Html页面上的多个Base64图像和平滑加载
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- 使用javascript检查多个输入值,并在1次检查中标记多个输入框
- KnockoutJS-组件-多个实例
- 用每小时的差值填充数组/列表-从下拉列表中给定两个时间值
- 科尔多瓦页面类应用程序中的多个谷歌地图
- 使用数据上的角度更改设置集合的第一个元素的动画
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- jQuery blueimp文件上传:将N-1个文件上传到IE中的服务器