My goal is to create a never-ending animation for a div element:
$(document).ready(function() {
function arrowmovement() {
setTimeout(function() {
$("#downarrowimg").animate({
'margin-top': "-=30px"
});
}, 500);
setTimeout(function() {
$("#downarrowimg").animate({
'margin-top': "+=30px"
});
}, 500);
}
arrowmovement();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="downarrow">
<img id="downarrowimg" src="https://upload.wikimedia.org/wikipedia/en/f/f1/Down_Arrow_Icon.png">
</div>
I am facing the issue of the animation running only once. Can someone help me identify what I am doing wrong and provide guidance on how to resolve it?