+ 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
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);
}
+ 2
setTimeout(addWidth(), 100); you are saying addWidth is a result your not activeting the function instead do setTimeout(addWidth, 100);
+ 2
Thank you guys :)
+ 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?
+ 1
Hmm Idk try using Debounce to make sure it doesnt twice
+ 1
Np



