javascript - 使用Javascript从右到左滚动进度条
问题描述
所以我有这个从左到右工作正常的进度条。虽然我试图让它从右到左工作。我尝试将最后一个属性设为父属性,然后遍历回来,但它不起作用。
$(document).ready(function(){
var current_fs, next_fs, previous_fs; //fieldsets
var opacity;
var current = 1;
var steps = $("fieldset").length;
setProgressBar(current);
$(".next").click(function(){
current_fs = $(this).parent();
next_fs = $(this).parent().next();
// var next_fs = $("#progressbar li:last").prev("li")
//Add Class Active
$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
//show the next fieldset
next_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now) {
// for making fielset appear animation
opacity = 1 - now;
current_fs.css({
'display': 'none',
'position': 'relative'
});
next_fs.css({'opacity': opacity});
},
duration: 500
});
setProgressBar(++current);
});
$(".previous").click(function(){
current_fs = $(this).parent();
previous_fs = $(this).parent().prev();
//Remove class active
// $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
//show the previous fieldset
previous_fs.show();
//hide the current fieldset with style
current_fs.animate({opacity: 0}, {
step: function(now) {
// for making fielset appear animation
opacity = 1 - now;
current_fs.css({
'display': 'none',
'position': 'relative'
});
previous_fs.css({'opacity': opacity});
},
duration: 500
});
setProgressBar(--current);
});
function setProgressBar(curStep){
var percent = parseFloat(100 / steps) * curStep;
percent = percent.toFixed();
$(".progress-bar")
.css("width",percent+"%")
}
$(".submit").click(function(){
return false;
})
});
以上是我正在使用的脚本,它不是从 RTL = 1 2 3 4 开始,而是转到 RTL 1 3 2 并停止并且没有达到四个
我还附上了所有代码的小提琴 https://jsfiddle.net/s327e1uo/1/
谢谢
解决方案
事实证明,我所要做的就是保持 JS 原样,并使其浮动:就在 css 中。在 (#ul li)
希望对任何人都有帮助
推荐阅读
- sql - 跨多个列 PostgreSQL/Rails 的慢速通配符搜索 LIKE
- python - Python 中 += 运算符的意外行为
- python - 如何增加 NumPy 数组的维度
- kubernetes - argocd:如何在 crd 中使用插件?
- javascript - React JS:如何实现类似gmail新消息窗口的弹窗
- python-3.x - 列表理解有效,但正常的 for 循环无效 - Python
- database - PL/SQL 如何选择和更新类型 IS TABLE OF
- java - Java扩展参数化类
- javascript - 如何测试在 react-testing-library 中调用了函数 prop
- wordpress - 如何将支付方式端点添加到 Woocommerce 中的帐户导航?