-1
If I check the collision only horizontally, the program picks up the entire width of the scene and not just the div.
Code:
<html>
<style>
#dv{
border:1px solid red;
background-color:#344;
height:80px;
position:absolute;
}
#dv2{
border:1px solid black;
background-color:#f00;
height:80px;
position:absolute;
}
</style>
<body>
<div id = "dv"></div>
<div id = "dv2"></div>
<script>
var valor = 0;
var valor2 = 180;
var dv= document.getElementById("dv");
var div2 = document.getElementById("dv2");
var largura = dv.style.width = 80;
var lateral = div2.style.left = 180;
var largura2 = div2.style.width = 80;
var lateral2 = div2.style.top = 300;
function moverDiv(){
valor += 5;
dv.style.left = valor+"px";
if(valor+largura > lateral){
div2.style.backgroundColor = "blue";
}
}
dv.addEventListener("touchmove",moverDiv);
</script>
</body>
</html>
Execution:
blz,but the big case is that the black div is above the red div and even so when I pass to the side it indentify that collided.
– Danilo Santos
@Danilosantos has to do the same for the y axis (vertical), see link example
– vik
Okay I’ll try that
– Danilo Santos
So it checks y and not x and the path is open to use the two intendi coordinates.So use the two strings.
– Danilo Santos
Thank you very much VIK
– Danilo Santos