I'm working on a javascript project in which I use a document fragment to append several span elements at once. Then they are animated with css.
.redCircle {
float: left;
height:20px;
width:20px;
border-radius:10px;
box-shadow: 0 0 20px red;
background-color: red;
animation: 2s circleFall linear;
}
@keyframes circleFall {
0%{margin:0;}
100%{margin:100% 10%;}
}
setInterval(thingyTime, 5000);
function thingyTime() {
var count = 15,
spanVar = document.createElement("span"),
fragment = document.createDocumentFragment();
for (var i = 0; i < count; ++i) {
for (var j = 0; j < 1; ++j) {
spanVar = document.createElement('spanVar');
spanVar.className = "redCircle";
fragment.appendChild(spanVar);
}
}
document.body.appendChild(fragment);
};
thingyTime();
I'm trying to figure out how to remove the spans after the animation is completed. I have used
setTimeout(function(){
spanVar.remove(spanVar.selectedIndex);
},2000); // <= animation length
and it works fine when it's only for one element, but I need to remove all the elements in the fragment.
I aprreciate your help.