I combine Alexandre Jasmin and Gab Le Roux answers like this:
[](https://www.youtube.com/watch?v=ek1j272iAmc)
Demo:
You can see this demo on github.
I used gifyoutube here, but I recommend using a local gif converter (like ffmpeg, see how) instead of an online one.
To record your screen to gif directly, you may want to check ScreenToGif.