+ 1

Help at setTimeout() please -_-

I try to set the width of an container slowly bigger ( with setTimeout() ) I tried more than 2 hours and im so frustrated ..... https://code.sololearn.com/WxHoBcP1YO6P/#html

23rd Dec 2018, 9:11 PM
Michelle Becker
Michelle Becker - avatar
6 odpowiedzi
+ 2
for animation use setInterval: var interval; function addWidth() { var lastValue = parseInt(MyObjects.container.style.width), newValue = lastValue + 1; MyObjects.container.style.width = newValue; if (newValue==500){ clearInterval(interval); } } function openAnimation() { interval=setInterval(addWidth, 10); }
23rd Dec 2018, 10:03 PM
Игорь Яковенко
Игорь Яковенко - avatar
+ 2
setTimeout(addWidth(), 100); you are saying addWidth is a result your not activeting the function instead do setTimeout(addWidth, 100);
23rd Dec 2018, 9:36 PM
Vanessa Nilsson
+ 2
Thank you guys :)
23rd Dec 2018, 10:12 PM
Michelle Becker
Michelle Becker - avatar
+ 1
@Skrub All right now the timeout makes an delay from 1 s but why is the for loop running through it the second time?
23rd Dec 2018, 10:00 PM
Michelle Becker
Michelle Becker - avatar
+ 1
Hmm Idk try using Debounce to make sure it doesnt twice
23rd Dec 2018, 10:04 PM
Vanessa Nilsson
+ 1
Np
23rd Dec 2018, 10:12 PM
Vanessa Nilsson