How JavaScript Judges collisions

Source: Internet
Author: User
/** to determine if collision * @param obj Original object * @param dobj target object/function impact (obj, dobj) {var o = {X:getdefa Ultstyle (obj, ' left '), Y:getdefaultstyle (obj, ' top '), W:getdefaultstyle (obj, ' width '), H: Getdefaultstyle (obj, ' height ')} var d = {X:getdefaultstyle (dobj, ' left '), Y:get  
    DefaultStyle (dobj, ' top '), W:getdefaultstyle (dobj, ' width '), H:getdefaultstyle (dobj, ' height ')  
      
    } var px, py; px = o.x <= d.x?  
    d.x:o.x; PY = o.y <= d.y?  
      
    D.Y:O.Y; Judge whether the point is in two objects//view this column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/if (px >= o.x &&am P  PX <= o.x + o.w && py >= o.y && py <= o.y + o.h && px >= d.x && px <= d.x +  
    D.W && py >= d.y && py <= d.y + d.h) {return true;  
    else {return false;  
   }  
}   
/** Get Object Properties * @param obj Object * @param attribute/function Getdefaultstyle (obj, attribute) {Retur n parseint (Obj.currentstyle? Obj.currentstyle[attribute]: Document.defaultView.getComputedStyle (obj, false) [  
Attribute]); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.