I'm trying repeat a function using SetInterval that shrinks and grows an image but it's not catching my flag so it keeps going in one direction rather than alternating the shrinking and growing.
function foo(toggle) {
let img = document.querySelector('.product-image')
if (img.style.width == "") { img.style.width = "0px"};
let width = parseInt(img.style.width.match(/\d+/g)[0])
if (toggle == false) {
width = width + 50;
img.style.width = width.toString() + "px"
img.style.transition = "all 2s"
toggle = true;
} else {
width = width - 50;
img.style.width = width.toString() + "px"
img.style.transition = "all 2s"
toggle = false;
}
}
let interval = setInterval(foo(false), 1000)