我是JQuery的新手,在淡出之后再加载时遇到了问题。
我的代码是:
$("#refresh").live("click", function() {
$("#postbit").fadeOut("slow");
$("#postbit").load('load.php').fadeIn("slow");
return false;
}); 但它似乎不起作用。如果我以前没有fadeOut,只是加载它,它工作得很好。但是,有没有一种方法可以先让它变得缓慢,然后让它慢慢地fadeIn :)
谢谢
发布于 2012-07-13 23:18:03
如果你正在使用jQuery 1.7或更高版本(如果你是新手),你就不应该再使用.live了,因为它不仅不好,而且在以后的版本中也会被删除。return false from events is also bad
// Change this to the known parent of #refresh
// Do you even need delegation?
$("#refresh").closest('*').on('click', '#refresh', function (e) {
// Callback to fadeOut (after fadeOut): load
$("#postbit").fadeOut('slow', function () {
// So you can reference this element without selector later
var $this = $(this);
// Callback to load -- takes place after load completes
$this.load('load.php', function () {
$this.fadeIn('slow');
});
});
// Prevent click from doing whatever it would normally do on #refresh
e.preventDefault();
});发布于 2012-07-13 23:13:20
与许多其他jQuery函数一样,.fadeOut()允许您指定在动画完成后执行的回调函数:
$("#refresh").live("click", function() {
$("#postbit").fadeOut("slow", function() {
$("#postbit").load('load.php').fadeIn("slow");
});
return false;
}); 这将在淡出动画完成后执行匿名函数(.fadeOut()的第二个arfument )中的代码。
顺便说一句,您不应该再使用.live(),因为它已被弃用,转而支持.on()。
https://stackoverflow.com/questions/11473255
复制相似问题