Protip - animated PNG is a thing, so no need to be limited to GIF's mere 256 color palette: https://caniuse.com/#feat=apng
As long as the image doesn't get downsized, the animation should be retained without issue.
(do note however that some APNG-creation software will output APNGs that are quite unoptimized resulting in huge file sizes, so running the exported APNG file through something like "APNG Optimizer" may be ideal)