好吧,我已經有了這個腳本工作。 ajax調用起作用並返回正確的數據。問題是,當快速按下擊鍵(不是真正的快速,只是正常的打字速度)時,動畫不斷前後移動,並且每個ajax調用仍然執行。jquery ajax onkeystroke停止動畫?
我怎樣才能讓這個:
1)Ajax調用不疊起來 和 2)淡入淡出和動畫不保持堆放
我有這個JavaScript :
$(document).ready(function(){
$t = $("#data-users");
$('#data-overlay').css({
opacity : 0.5,
top : $t.offset().top,
width : $t.outerWidth(),
height : $t.outerHeight()
});
$('.loader').css({
top : ($t.height()/2),
left : ($t.width()/2)
});
$('.findit').keyup(function(){
var search;
search = $(this).val();
$('#data-overlay').fadeIn();
//get the data
$.post(
'/users/testajax',
{
search: search
},
function(responseText){
$("#data-users").html(responseText);
$('#data-overlay').fadeOut();
},
'html'
);
});
});
對於動畫的問題,請致電'.stop()'.fadeIn前'()'。 – Michal 2010-07-09 18:46:48