我可以在JQuery中添加appendTo,但是淡入而不是立即出现吗? [英] Can I appendTo in JQuery, but have it fade in rather than instantly appear?

查看:65
本文介绍了我可以在JQuery中添加appendTo,但是淡入而不是立即出现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,我有一个JQuery模板,并且正在使用.tmpl将其附加到div.我的代码是:

Specifically, I have a JQuery template, and I am using .tmpl to append it to a div. My code is:

$("#" + this.templateID).tmpl({ results: resultsArray }).appendTo("#" + this.targetID);

这会在div末尾破坏我的模板.但是,我想淡入它.我不想在页面上创建一个额外的div.

This whacks my template at the end of the div. However, I want to fade it in. I don't want to create an extra div on the page.

理想情况下,我想做的是将模板化的数据添加到页面,然后选择最外面的元素并将其设置为不显示任何元素,从而使其看起来不可见.然后告诉它淡入,以便生成的标记与页面上已经存在的其他项目无缝匹配.

Ideally what I'd like to do is add the templated data to the page, and select the outermost element and set it to display none so it appears invisibly. Then tell it to fade in, so the resulting markup matches the other items already on the page seamlessly.

任何想法如何做到这一点?

Any ideas how to do this?

推荐答案

向其添加第一个.hide(),并在添加后使用.fadeIn().

Add first .hide() to it and the use .fadeIn() after appending it.

因此:

$("#" + this.templateID)
    .tmpl({ results: resultsArray })
    .hide()
    .appendTo("#" + this.targetID)
    .fadeIn();

这篇关于我可以在JQuery中添加appendTo,但是淡入而不是立即出现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆