I'm trying to make an image fall, similar to a rain effect, but I only want it triggered by an event listener.
Currently, I'm appending a div and animating the falling effect, but each additional event trigger is then appended below/next to the first.
function appendImage() {
var img = document.createElement('img');
img.setAttribute('src', 'http://pixelartmaker.com/art/3ba7f5717ac3c63.png');
$('#action').append(img);
}
@keyframes slidedown {
0% {
margin-top: 0%;
}
100% {
margin-top: 150%;
}
}
img {
animation-duration: 20s;
animation-name: slidedown;
height: 100px;
width: 100px;
}
<input type="button" value="Test Button" onclick="appendImage();" />
<div id="action"></div>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
I'm trying to get the image to spawn from a random place on the x axis but always from the top of the screen.
codepen here.