如何向附加添加淡入淡出?
我无法适应我在 stackoverflow 中找到的描述如何向附加添加淡入淡出的示例,并且我无法弄清楚原因。
我有以下代码,用于使用 ajax 将联系表单替换为成功消息:
$.ajax({
type: "POST",
url: "contact-engine.php",
data: dataString,
success: function() {
$('#contact-form').html("<div id='message-form'></div>");
$('#message-form').html("<h3>Your message has been submitted successfully!</h3>")
.hide()
.fadeIn(2000, function() {
$('#message-form').append('<p style="text-align:center">Thanks for getting in touch. I will get back to you as soon as possible.</p>');
});
}
});
return false;
我试图让追加淡入。我尝试在追加 html 之后添加 .hide().fadeIn(2000) ,但这并没有'不工作。有人可以帮我解决这个问题吗?
谢谢,
尼克
I haven't been able to adapt the examples I have found in stackoverflow that describe how to add a fade to an append, and I can't work out why.
I have the following code for using ajax to replace a contact form with a success message:
$.ajax({
type: "POST",
url: "contact-engine.php",
data: dataString,
success: function() {
$('#contact-form').html("<div id='message-form'></div>");
$('#message-form').html("<h3>Your message has been submitted successfully!</h3>")
.hide()
.fadeIn(2000, function() {
$('#message-form').append('<p style="text-align:center">Thanks for getting in touch. I will get back to you as soon as possible.</p>');
});
}
});
return false;
I am trying to get the append to fade in. I tried adding .hide().fadeIn(2000) after the append html, but this didn't work. Could someone help me out with this?
Thanks,
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您在
append
之后添加hide
和fadeIn
,问题是您将隐藏和淡入容器,而不是您要添加的元素。如果将其更改为appendTo
它应该可以工作:示例:http://jsfiddle.net/ U4d9G/
If you add
hide
andfadeIn
afterappend
, the problem is that you will be hiding and fading the container, not the element you are adding. If you change it toappendTo
it should work:An example: http://jsfiddle.net/U4d9G/
我更喜欢在附加之前隐藏......
像这样的事情:
I prefer to hide before the append....
Something like this: