JSFiddle - React, Tailwind, and code Playground

HTML

<img id="one"/>
<img id="two"/>

JavaScript

function onload_animate(id_name, img_src1, img_src2, time_ms) {
    document.getElementById(id_name).src = img_src1;

    setTimeout(function () {
        onload_animate(id_name, img_src2, img_src1, time_ms);
    }, time_ms);
};

onload_animate("one", "http://files.mattlunn.me.uk/permanent/fish_images/1.jpg", "http://files.mattlunn.me.uk/permanent/fish_images/2.jpg", 500);