jQuery 的 fadeIn() 和 fadeIn() 的困难隐藏()
我猜我误解了如何完成我通过 jquery.form.js 添加的元素的 fadeIn() ,但是在尝试了我在其他帖子上找到的东西之后我却一无所获。我仍在学习 jQuery 和 javascript,所以也许我的错误很简单。
在我的 jquery.form.js ajaxForm 的成功中,我有以下代码行
jQuery('#aThankYouTarget').append(jQuery("<p>"+data+"</p>")).fadeIn(1000);
我已经尝试了该行的变体,但似乎看不到褪色结果。我的数据完全符合预期,只是没有褪色。我也尝试过将 hide() 放入如下所示,但是当我这样做时,隐藏似乎可以工作,但淡入也永远不会发生在那里。
jQuery('#aThankYouTarget').append(jQuery("<p>"+data+"</p>").hide()).fadeIn(1000);
另外,正如这里另一个问题所建议的那样,我尝试了如下数据。我认为无论如何我都使用了“文本”,因为我早已忘记了当它不起作用时那个人的建议。
jQuery('#aThankYouTarget').append(jQuery("<p></p>").text(data.content).hide()).fadeIn(1000);
我真的更喜欢类似于我的第一个示例的东西,因为它使 javascript 的段落部分看起来最像 html 最终的样子,而且我觉得它更容易阅读,但如果有人想说服我创建该元素,并为其添加文本,我可能会被说服。最主要的是我找到了如何让 fadeIn() 工作。
谢谢。
编辑:#aThankYouTarget 是一个 div,里面有段落。当页面加载时,某些段落可能已经存在。我想要做的淡入是让表单提交后任何新添加的段落淡入。
I'm guessing I am misunderstanding how to accomplish a fadeIn() of an element which I am adding via jquery.form.js, but after trying things I've found on other posts I have gotten nowhere. I'm still learning jQuery and javascript so maybe my error is something simple there.
I have the following line of code in the success of my jquery.form.js ajaxForm
jQuery('#aThankYouTarget').append(jQuery("<p>"+data+"</p>")).fadeIn(1000);
I have tried variations on this line and cannot seem to see fading results. My data is coming up exactly as expected, it just lacks the fade. I have also tried putting a hide() in like follows, but when I do that the hide seems to work but the fadeIn never happens there either.
jQuery('#aThankYouTarget').append(jQuery("<p>"+data+"</p>").hide()).fadeIn(1000);
Also as suggested on another question here I have tried with data as follows. I think it was "text" that I used anyway, as I have long since forgotten what that person suggested when it wasn't working either.
jQuery('#aThankYouTarget').append(jQuery("<p></p>").text(data.content).hide()).fadeIn(1000);
I'd really prefer something similar to my first example as it keeps the paragraph section of the javascript looking the most like the html will in the end and I feel it is easier to read, but if someone wants to talk me into creating the element, and adding text to it I could probably be persuaded. The main thing is that I find out how to get the fadeIn() working.
Thank you.
Edit: #aThankYouTarget is a div, with paragraphs inside of it. When the page is loaded some paragraphs are possibly already there. The fadeIn I wish to do is for any newly added paragraphs after the form submission to fade in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你们非常接近。您确实需要先
.hide()
,但您淡出是错误的!注意:交换顺序,使
成为主要对象。
.hide()
和.fadeIn()
现在都将在上运行,在之后已附加。
You were awfully close. You do need to
.hide()
first, but you were fading the wrong thing!Note: switched the order around so that the
<p>
becomes the main object..hide()
and.fadeIn()
will now both operate on the<p>
, after it has been appended.