The original post is here.
The explanation is inside the code.
I'm using free tiles from GameArt2D, that I assembled in a single spritesheet file.
Note: The spritesheet was roughly made, do not be picky about the quality of it
How to animate a character with multiple different actions and directions with one single spritesheet
JavaScript