我对 jQuery ajax 和动画有一点问题。我有一个带有菜单的布局,该菜单调用我的页面,加载时提供一点动画jQuery easing
这是我的ajax.js
$(document).ready(function() {
// Ajax request
$(".transition").click(function() {
page = ( $(this).attr("id") );
$.ajax({
type: "GET",
url: page,
data: "ajax=true",
cache: false,
success: function(html) {
afficher(html);
},
error: function(XMLHttpRequest,textStatus,errorThrows) {
// Erreur durant la requête
}
});
});
function afficher(donnees) {
$(".step").empty();
$(".step").append(donnees);
// Animate
var step_position = $(".step").offset();
$(".step").offset({ top: step_position.top, left: step_position.left - 1000 });
$(".step").animate({
"left": '+=1000',
}, 750, 'easeOutBack');
}
});
如果用户点击,一切都会很好。
但如果:
- 用户双击同一链接
- 用户快速点击多个链接
然后加载的数据离开页面。
我知道我使用异步数据并且我要求offset
在准确的时间这一事实存在问题。我试图将常量作为参数(而不是做var step_position = $(".step").offset();
),但这没有用。
无论进行了多少次 ajax 调用,我应该如何始终正确显示我的数据?