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?
            Asked
            
        
        
            Active
            
        
            Viewed 1,749 times
        
    1
            
            
        - 
                    Does this help? http://stackoverflow.com/questions/4230029/jquery-javascript-collision-detection – Christian Nov 24 '11 at 01:41
- 
                    This did get me in the right direction I will try and find out more on Collisions. – Zakukashi Nov 24 '11 at 01:51
2 Answers
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
