jQuery 的 fadeIn() 和 fadeIn() 的困难隐藏()

发布于 2024-10-10 22:51:14 字数 943 浏览 1 评论 0原文

我猜我误解了如何完成我通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤独陪着我 2024-10-17 22:51:14

你们非常接近。您确实需要先.hide(),但您淡出是错误的!

jQuery("<p>"+data+"</p>").appendTo('#aThankYouTarget').hide().fadeIn(1000);

注意:交换顺序,使

成为主要对象。 .hide().fadeIn() 现在都将在

上运行,之后已附加。

You were awfully close. You do need to .hide() first, but you were fading the wrong thing!

jQuery("<p>"+data+"</p>").appendTo('#aThankYouTarget').hide().fadeIn(1000);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文