1

So I've been able to check if two images have the same top css value with:

if($('#pic').top == $('#pic1').top){
        alert("You lose");
    }

But I want to check if they overlap, so they will not necessarily have the same top value. So, I've tried this:

if(parseInt($('#pic').top) < parseInt($('#pic1').top) + 99){
        alert("You lose");
    }

It does not work. How can I fix this? Note: I am using 99 because the height of the images are 100.

Jona
  • 29
  • 3
  • There is a similar question in here: http://stackoverflow.com/questions/5419134/how-to-detect-if-two-divs-touch-with-jquery – drip Nov 29 '15 at 09:05
  • I can't imagine your code would work in the first place since `object.top` isn't anything valid. – Shikkediel Nov 29 '15 at 09:20
  • Shikkediel yes, the first snippet of code actually works. – Jona Nov 29 '15 at 17:38
  • I think you are getting `undefined == undefined` there... so it only appears to be so. That is probably why the second one doesn't work. You could give `$('#pic').offset().top` a try. Then there's also no need to parse them as integer because that will already return a value without pixels. – Shikkediel Nov 30 '15 at 09:45

0 Answers0