0
我已經創建了一個循序漸進的演練。每個步驟都包含在一個單獨的「fieldset」中,整個文件是一個.html文件。動畫div/fieldset中的多步表單
向前和向後移動我使用JavaScript。 問題是,隨着時間的推移,動畫開始滯後。
在附件中的例子中,一切正常,因爲內容很少。 優化問題在哪裏?
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'
});
});