我有一个联系人脚本。它使用jQuery进行ajax请求和动画。
我还使用它与hashchange插件一起来解决后退按钮问题。慢的部分在这里。
在完成“翻转”的动画后,表单会缓慢地消失。浏览器似乎会阻塞一秒钟。我正在尝试使它更加快速(无阻塞)。
以下是负责处理哈希更改事件的函数:
整个代码可以从下面的链接中查看,它已经完全记录:
如果有人想看到慢速,请尝试从下面的链接发送一条空消息(验证已禁用),然后单击浏览器中的后退按钮:
(注意:它不是英语,但我猜它相当容易理解^^) 那我该如何使它更加流畅?
我还使用它与hashchange插件一起来解决后退按钮问题。慢的部分在这里。
在完成“翻转”的动画后,表单会缓慢地消失。浏览器似乎会阻塞一秒钟。我正在尝试使它更加快速(无阻塞)。
以下是负责处理哈希更改事件的函数:
handleHashChange : function () {
// Get the name of the object and cache it
var self = this,
// Get the current hash
hash = window.location.hash,
// Cache the form height var
formHeight = '';
// If the hash is #send or #error, don't do anything
if (hash === "#sent" || hash === "#error") {
return;
}
// Change the page title back to the default
if(self.documentTitle && self.documentTitle != undefined) {
document.title = self.documentTitle;
}
// Reset all inputs in the form
self.inputs.val('').removeAttr('checked').removeAttr('selected');
// Get the height of the form
formHeight = self.getHeight(self.form);
// Show the transition
self.showTransition(self.response, formHeight, function() {
// Show the form
self.form.fadeIn('fast', function() {
// Show the button
self.button[0].style.display = 'block';
// Focus the first input
self.inputs[0].focus();
})
})
}
整个代码可以从下面的链接中查看,它已经完全记录:
http://www.coolcontact.co.cc/beta/1.3/js/main.js
你可以看到,我在优化这个脚本时使用了很多在互联网上找到的技巧,除了使用javascript原生的'for'代替'$ .each()',但这在这里并不是很重要。如果有人想看到慢速,请尝试从下面的链接发送一条空消息(验证已禁用),然后单击浏览器中的后退按钮:
(注意:它不是英语,但我猜它相当容易理解^^) 那我该如何使它更加流畅?