My goal was to run one function at a time, but my functions that move the square are running together and I do not know how to do one run only after the other ends. Here's the code:
css:
#caixa1{
width: 200px;
height: 200px;
background: green;
position: relative;
}
#caixa2{
width: 50px;
height: 50px;
background: red;
position: absolute;
}
html:
<body>
<div id="caixa1">
<div id="caixa2">
</div>
</div>
</body>
javascript:
var posH = 0
var posL = 0
var caixinha = document.getElementById("caixa2")
var intervaloL = setInterval(movL,10)
var intervaloH = setInterval(movH,10)
//left = ir pro lado direito
//top = vai pra baixo
function movL()
{
if(posL >= 150)
{
caixinha.style.left = posL +'px'
}else{
posL += 1
caixinha.style.left = posL + "PX"
}
}
function movH()
{
if(posH >= 150)
{
caixinha.style.top = posL +'px'
}else{
posH += 1
caixinha.style.top = posH + 'px'
}
}