In elementFromPoint (x, y) of IE8, x and y cannot be non-immediate at the same time, so you can write an alternative function.
[Javascript]
/*
* This function is used to simulate: elementFromPoint.
* Obtain the class attribute tagCls and the best element of the client location (x, y) of the parent element.
* Return el;
*/
GetPerfectTag: function (parent, tagCls, x, y ){
// Filter at the first layer: All elements with tagCls under the parent
Var children = KISSY. DOM. query ('.' + tagCls, parent );
Tags = [];
If (children. length = 0) return null;
// Layer 2 filtering: elements containing (x, y) points
Tags = getInXY (children );
Function getInXY (children ){
Var tags = [];
Hx. each (children, function (item ){
Var x0 = item. offsetLeft,
Y0 = item. offsetTop,
X1 = x0 + item. offsetWidth,
Y1 = y0 + item. offsetHeight;
// This item contains the point where the mouse is located
If (x0 <= x & x1> = x) & (y0 <= y & y1> = y )){
Var obj = {
Item: item,
Zindex: Items (item).css ('zindex') | null,
IsTop: $ (item). children ("." + tagCls). length = 0 // whether its child does not contain tagCls
};
Tags. push (obj );
}
});
Return tags;
}
Var len = tags. length; www.2cto.com
// If all the elements that contain tagCls do not contain (x, y), you need to find all descendant elements of children. Because the child element may deviate from the box model of the parent element.
If (len = 0 ){
Var tag;
Function getAllChildren (el, all ){
Var all = all | [];
If (el = null) return null;
All. push (el );
Hx. each ($ (el). children (), function (item ){
GetAllChildren (item, all );
});
Return all;
}
// Search for all descendant elements that meet tagCls one by one, and put the set into (x, y) for matching. If the matching is successful, the search is successful.
Hx. each (children, function (item ){
Var all = getAllChildren (item );
Var temps = getInXY (all );
If (temps. length> 0 ){
Tag = temps [0]. item;
Return false;
}
});
Return tag;
}