Sunday 15 April 2012

jquery - JavaScript: Trigger a function when two divs touch / overlap -


The title really tells how to do it? Both devices are of different sizes both divs are moving forward (I'm making a little Jquery game). If one kills each other, then I want to get stuff.

Thanks

There is no JavaScript event for overlapping, you can calculate this Whether to divide your overlapping by:

  var valueInRange = function (value, min, max) {return (value> = min)) and amp; Amp; (Value & lt; = max); } Var overlap = function (x1, y1, w1, h1, x2, y2, w2, h2) {xOverlap = valueInRange (x1, x2, x2 + w2) || Mannarange (X2, X1, X1 + W1); YOverlap = valueInRange (y1, y2, y2 + h2) || Mannarange (y2, y1, y1 + h1); Return x overlap & amp; Amp; YOverlap; }  

No comments:

Post a Comment