You would need custom code or a third party plugin for this.
Specifically, for custom code, you would need Javascript which is out of our scope of support. It would be best to reach out to a developer or ask for recommendations in our Facebook Group: https://www.facebook.com/groups/1113359788719597
if you’re studying frontend development then i would suggest you develop a plugin for that.
As a general rule and script libraries you want to install you would use wp_enqueue_script