1

I'm trying to figure out how to select certain Elements within a selected rectangle. The current method loops all elements and gets their X/Y if they are greater than rectangle's X/Y and less than rectangle's H/W then it gets selected. The problem with this method is, the rectangle has to be less than the Elements X/y EVEN though half of the element is inside the rectangle. Is there a nice jQuery solution to this, like find out if an element is inside the rectangle or even a tiny bit of it is inside? or maybe an easier approach with JavaScript?

Ry-
  • 218,210
  • 55
  • 464
  • 476
Zakukashi
  • 566
  • 1
  • 13
  • 29

2 Answers2

3
if(
       ( ( Left1 + Width1 ) >= Left2 )
    && ( Left1 <= ( Left2 + Width2 ) )
    && ( ( Top1 + Height1 ) >= Top2 )
    && ( Top1 <= ( Top2 + Height2 ) )
)
0

To get the width and height of any given element, you can use the jQuery width() and height() functions, respectively. Then, just add the width and height to the X and Y before comparing.

Ry-
  • 218,210
  • 55
  • 464
  • 476