Idea: Loop GSAP Animation on Hover

Have a “Loop animation while on hover” option.
Here’s some example code to give an idea:

var hover = false;

document.querySelector(“.nice-block”).addEventListener(“mouseenter”, hoverOn);
document.querySelector(“.nice-block”).addEventListener(“mouseleave”, hoverOff);
const tween = gsap.to(“.animated-block”, { duration: 1, x: 50, repeat: 1, yoyo: true, ease: “sine.inOut”, paused:true, onComplete:checkHover});

function checkHover() {
if(hover){
tween.restart()
}
}

function hoverOn() {
hover = true
tween.play()
console.log(tween.progress())
if(tween.progress() == 0){
tween.restart() //not sure why play() doesn’t work when progress() == 0
}
}

function hoverOff() {
hover = false
}

What do you think about this idea?