JQuery - 创建后淡出元素 [英] JQuery - Fade Out Elements After Being Created
问题描述
我目前正在开发一个JQuery游戏(只是为了使用JQuery)并且在某些碰撞中,会创建一个爆炸类。
I'm currently working on a JQuery game (Just to get around with using JQuery) and on certain collisions, an "explosion" class is created.
现在我正在使用 $(#game)。append(div html code goes here)
将其添加到游戏div中。现在,如何在创建元素后创建它,它在创建后淡出?我尝试按照 $(。explosion)的方式做一些事情.load(函数在这里)
但这似乎不起作用:\
Right now I'm using $("#game").append("the div html code goes here")
to add it in the game div. Now, how do I make it so after the element is created, it fades out after being created? I tried doing something along the lines of $(".explosion").load(function goes here)
but that doesn't seem to work :\
推荐答案
你可以这样做:
$("the div html code goes here").appendTo("#game").fadeOut();
如果你想在淡出之后摆脱它,你可以这样做:
If you want to get rid of it after it fades out, you can do this:
$("the div html code goes here").appendTo("#game").fadeOut(function() {
$(this).remove();
});
在这里工作演示: http://jsfiddle.net/jfriend00/qbJgh/
这篇关于JQuery - 创建后淡出元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!