I'm fairly new to coding / javascript and was wanting to get feedback on a method I'm using. I got frustrated trying to import multiple adobe animate html5/javascript files so I reverted to:
- exporting the animations frame by frame (.png)
- using javascript to call a local file and change the 'src' of a div given a specific interval
filename1 - is the folder file filename - is the .png filename
Is this bad practice or is there better more efficient way to do this? I plan on having it triggered in an interactive site when users click on different areas of an image. Worried the constant calling of files could be an issue and I'm unsure what would happen if someone triggered a new animation while one was still running?
So far it seems to be running okay, it does 'jitter' every once and a while if I interact with the site while an animation is running.
function playTargetAnimation (filename1,filename) {
let i = 1;
$('#'+filename1).attr('src', "images/" + filename1 +"/" + filename +"/" + filename + '0001' + ".png");
$('#'+filename1).show();
let runAnim = setInterval(function(){
let imgCnt = "00" + ("0" + i).slice(-2);
$('#'+filename1).attr('src', "images/" + filename1 +"/" + filename +"/" + filename + imgCnt + ".png");
console.log('src', "images/" + filename +"/" + filename + imgCnt + ".png");
i++;
if(i === 41) {
clearInterval(runAnim);
};
}, 25);
}