Last active
March 20, 2016 10:27
-
-
Save Gourdboy/aa211b29ffcbc4887a28 to your computer and use it in GitHub Desktop.
检测两个矩形dom是否重叠或求重叠的大小
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isRegionOverlap(region1, region2) { | |
var min = Math.min; | |
var max = Math.max; | |
var left = max(region1.left,region2.left); | |
var top = min(-region1.top,-region2.top); | |
var right = min(region1.right,region2.right); | |
var bottom = max(-region1.bottom,-region2.bottom); | |
return right > left && top > bottom; | |
} | |
function isOverlap(dom1,dom2){ | |
var region1 = dom1.getBoundingClientRect(); | |
var region2 = dom2.getBoundingClientRect(); | |
return overlapRegion(region1,region2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment