JQuery - 创建后淡出元素

InV*_*ert 2 javascript jquery

我目前正在开发一个JQuery游戏(只是为了使用JQuery)并且在某些碰撞中,会创建一个"爆炸"类.

现在我正在使用$("#game").append("the div html code goes here")它添加到游戏div中.现在,如何在创建元素后创建它,它在创建后淡出?我试着做一些事情,$(".explosion").load(function goes here)但似乎没有用:

jfr*_*d00 6

你可以这样做:

$("the div html code goes here").appendTo("#game").fadeOut();
Run Code Online (Sandbox Code Playgroud)

如果你想在淡出之后摆脱它,你可以这样做:

$("the div html code goes here").appendTo("#game").fadeOut(function() {
    $(this).remove();
});
Run Code Online (Sandbox Code Playgroud)

这里的工作演示: http ://jsfiddle.net/jfriend00/qbJgh/