Skip to content

Instantly share code, notes, and snippets.

@Gourdboy
Gourdboy / gist:aa211b29ffcbc4887a28
Last active March 20, 2016 10:27
检测两个矩形dom是否重叠或求重叠的大小
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;
}
/**
* Fetches and inserts a script into the page before the first
* pre-existing script element, and optionally calls a callback
* on completion.
*
* [TODO] Make this a module of its own so it can be used elsewhere.
*
* @param {String} src source of the script
* @param {Function} callback (optional) onload callback
*/