I'm trying to detect a collision between two elements and I'm facing problems when using the css3 translate3d instead of making use of the top property.
Problems take place in:
- Chrome (35.0.1916.153 m)
- Opera (22.0.1471.70)
When using translate3d there's a delay detecting the collision. I'm using setInterval with a lapse of 1 millisecond to make sure the position of both elements is being monitored almost in real time.
In my examples, the small square will become black when the collision is detected. As you can see, the delay sometimes is quite big, sometimes the collision seems to be detected when the animation is finished.
Working properly when modifying the top property:
http://jsfiddle.net/rHZbt/10/
Delay when using translate3d instead to move the elements:
http://jsfiddle.net/rHZbt/9/
This is the way I detect the collision with jQuery:
var interval = setInterval(function () {
checkCollision();
}, 1);
function checkCollision() {
var top = $('#element').offset().top;
var bigBoxTop = $('#demo').offset().top + $('#demo').height();
if (bigBoxTop >= top) {
$('#element').css('background', 'black');
clearInterval(interval);
}
}
Any ideas of what's the cause of this bug?