我使用jQuery爲CMS中的登錄表單構建簡單的動畫。 jQuery切換兩種形式,登錄表單和重置密碼錶單的可見性。在jQuery登錄腳本中重構動畫
該腳本工作得很好,但我似乎想出如何縮短它,因爲大部分代碼是多餘的。
注:.click
函數在每種情況下被調用兩次以強制動畫同時發生。
的JS:
$(function() {
var recover_text = "Password Recovery";
var login_text = "Login to CMS";
$("input").labelify({ text: "label", labelledClass: "inside" });
$("#forgot").click(function() {
$("#cms_login").fadeOut("fast", function() {
$("#pw_recover").fadeIn();
});
});
$("#forgot").click(function() {
$("#dialog h2").fadeOut("fast", function() {
$(this).html("" + recover_text + "").fadeIn();
});
document.title = '' + recover_text + '';
});
$("#login").click(function() {
$("#pw_recover").fadeOut("fast", function() {
$("#cms_login").fadeIn();
});
});
$("#login").click(function() {
$("#dialog h2").fadeOut("fast", function() {
$(this).html("" + login_text + "").fadeIn();
});
document.title = '' + login_text + '';
});
});
而且(有刪節)HTML:
<div id="form-wrap">
<form id="cms_login">
...login fields...
<a id="forgot" href="#">Forgot password?</a>
</form>
<form id="pw_recover">
...reset password fields...
<a id="login" href="#">⇐ Back to login</a>
</form>
</div>
#pw_recover { display: none; }
如何優化/重新裝備這個腳本?有什麼想法嗎?
太棒了!現在,在哪裏插入`return false`以防止頁面跳到頂部? – peehskcalba 2009-07-24 17:35:31