gpt4 book ai didi

javascript - 动画 div/fieldset 中的多步表单

转载 作者:行者123 更新时间:2023-11-28 03:53:48 25 4
gpt4 key购买 nike

我已经创建了一个分步演练。每个步骤都包含在一个单独的“字段集”中,整个是一个 .html 文件。

为了前进和后退,我使用 javascript。问题是随着时间的推移,动画开始滞后。

在附带的示例中,一切正常,因为内容很少。优化的问题在哪里?

JsFiddle

HTML:

 <form id="msform">
<fieldset id="firstField">
<input type="button" name="subject1" class="next action-button" value="Subject1 />
<input type="button" name="subject2" class="next action-button" value="Subject2 />
<input type="button" name="subject3" class="next action-button" value="Subject3 />
</fieldset>
<fieldset id="subject1">
<h2>Some text</h2>
<input type="button" name="prev" class="back action-button" value="Back" />
<input type="button" name="previous" class="previous action-button" value="Reset" />
</fieldset>
</form>

Javascript:

  var current_fs, next_fs, previous_fs, back_fs;
var left, opacity, scale;
var animating;
var progress = [];
var message = "Funkcja niedostępna.";
$(".next").click(function() {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
next_fs = $('#' + $(this).attr('name'));

$("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
progress.push($('fieldset:visible'));

next_fs.show();
current_fs.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 1 - (1 - now) * 0.2;
left = (now * 50) + "%";
opacity = 1 - now;
next_fs.css({
'left': left,
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_fs.hide();
animating = false;
},
easing: 'easeInOutBack'
});
});
$(".previous").click(function() {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
previous_fs = $('#firstField');

$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

previous_fs.show();
current_fs.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 0.8 + (1 - now) * 0.2;
left = ((1 - now) * 50) + "%";
opacity = 1 - now;
current_fs.css({
'left': left
});
previous_fs.css({
'transform': 'scale(' + scale + ')',
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_fs.hide();
animating = false;
},
easing: 'easeInOutBack'
});
});
$(".back").click(function() {
if (animating) return false;
animating = true;
current_fs = $(this).parent();
$("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");

back_fs = progress.pop();
back_fs.show();
current_fs.animate({
opacity: 0
}, {
step: function(now, mx) {
scale = 0.8 + (1 - now) * 0.2;
left = ((1 - now) * 50) + "%";
opacity = 1 - now;
current_fs.css({
'left': left
});
back_fs.css({
'transform': 'scale(' + scale + ')',
'opacity': opacity
});
},
duration: 800,
complete: function() {
current_fs.hide();
animating = false;
},
easing: 'easeInOutBack'
});
});

最佳答案

您是否曾让按钮在 div 中起作用?

我下载了相同的“使用 jQuery 和 CSS3 的带有进度条的多步骤表单”。

我能够显示带有 div 的字段集,但实际的按钮...除非在 div 之外,否则 onclick 不起作用。

所以当这进行到下一步

  <fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password" />
<input type="button" name="next" class="next action-button" value="Next" />

虽然这个没有

  <fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password" />
<div class="pull-right">
<input type="button" name="next" class="next action-button" value="Next" />
</div>

没有什么是我没试过的...即使删除动画也行不通

回答你的问题... :)

我更改了我的 JS 以禁用(注释掉)尽可能多的动画并将持续时间设置为 000...

//jQuery time
var current_fs, next_fs, previous_fs; //fieldsets
var opacity; //fieldset properties which we will animate
var animating; //flag to prevent quick multi-click glitches

$(".next").click(function(){
if(animating) return false;
animating = true;

current_fs = $(this).parent();
next_fs = $(this).parent().next();

//activate next step on progressbar using the index of next_fs
$("#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, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale current_fs down to 80%
//scale = 1 - (1 - now) * 0.2;
//2. bring next_fs from the right(50%)
//left = (now * 50)+"%";
//3. increase opacity of next_fs to 1 as it moves in
opacity = 1 - now;
//current_fs.css({'transform': 'scale('+scale+')'});
current_fs.css({'opacity': opacity});
//next_fs.css({'left': left, 'opacity': opacity});
next_fs.css({'opacity': opacity});
},
duration: 000,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});

$(".previous").click(function(){
if(animating) return false;
animating = true;

current_fs = $(this).parent();
previous_fs = $(this).parent().prev();

//de-activate current step on progressbar
$("#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, mx) {
//as the opacity of current_fs reduces to 0 - stored in "now"
//1. scale previous_fs from 80% to 100%
//scale = 0.8 + (1 - now) * 0.2;
//2. take current_fs to the right(50%) - from 0%
//left = ((1-now) * 50)+"%";
//3. increase opacity of previous_fs to 1 as it moves in
opacity = 1 - now;
//current_fs.css({'left': left});
current_fs.css({'opacity': opacity});
//previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
previous_fs.css({'opacity': opacity});
},
duration: 000,
complete: function(){
current_fs.hide();
animating = false;
},
//this comes from the custom easing plugin
easing: 'easeInOutBack'
});
});

关于javascript - 动画 div/fieldset 中的多步表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43589713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com