Can I appendTo in JQuery, but have it fade in rather than instantly appear?

怎甘沉沦 提交于 2019-12-07 10:12:41

问题


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);

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?


回答1:


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

Thus:

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


来源:https://stackoverflow.com/questions/6265778/can-i-appendto-in-jquery-but-have-it-fade-in-rather-than-instantly-appear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!