我想要的是非常简单,但我正在努力学习语法。单击我的元素时,我希望触发我的动画,然后在.css()之后触发。预先感谢您的帮助。干杯。马克。
$('.content').click(function() {
$('#contentWrapper').animate({
"left": "-=475px"}, "fast"),
$(this).prev().css("display": "none");
});
答案 0 :(得分:4)
几乎。您需要在animate
上传递complete
参数函数引用:
$('.content').click(function() {
$('#contentWrapper').animate({
"left": "-=475px"}, "fast", function () {
$(this).prev().css("display", "none");
}
);
});
(另外,css
的语法有点偏离,您希望,
代替:
)
答案 1 :(得分:2)
您应该提供第二个函数作为回调
$('.content').click(function() {
$('#contentWrapper').animate({
"left": "-=475px"}, "fast", $(this).prev().css("display": "none"));
});
});
编辑 - 我认为以这种方式this
指向被点击的元素。如果不是你应该做的
$('.content').click(function() {
var that = this;
$('#contentWrapper').animate({
"left": "-=475px"}, "fast", $(that).prev().css("display": "none"));
});
});
答案 2 :(得分:1)
您提供第二部分作为回调函数,这意味着它在第一个函数完成后执行。如果您使用相同元素作为第一个动画,那么您可以使用链接('我不确定您是否可以在这种情况下使用它,因为您没有'提供html)。
$('.content').click(function() {
$('#contentWrapper').animate(
{"left": "-=475px"},
"fast",
function(){
$(this).prev().css("display": "none");
}
);
});