function sameSign(a, b){
return(a ^ b) >=0
}
//位运算,判断符号是否相同a异或b
function vector(a, b){
return {
x: b.x - a.x,
y: b.y - a.y
}
}
//向量的坐标
//向量的差乘公式
function vectorProduct(v1,v2){
return v1.x * v2.y - v2.x *v1.y
}
function isPointInTrangle(p,a,b,c) {
var pa = vector(p,a)
var pb = vector(p,b)
var pc = vector(p,c)
var t1 = vectorProduct(pa,pb)
var t2 = vectorProduct(pb,pc)
var t3 = vectorProduct(pc,pa)
return sameSign(t1,t2) && sameSign(t2,t3)
}
function needDelay(elem,leftCorner,currMoussePos) {
var offset = elem.offset()
//offset方法来获取二级菜单上下边缘的坐标
var topleft = {
x: offset.left,
y: offset.top
}
var bottomleft = {
x: offset.left,
y: offset.top + elem.height()
}
return isPointInTrangle(currMoussePos,leftCorner,topleft,bottomleft)
}