Closed sonicsunsky closed 5 years ago
这个方法是获取某个元素所支持的弹出菜单箭头方位,由上右下左中组合而成,每个方向有三种方位,一共上下左右四个方向,3x4=12
,例如:弹出菜单箭头朝上,那么就有:上左、上中、上右三种方位
嗯,大概思路知道了,主要还是对于代码里的一些变量的含义还是不太明确,比如: boxTotalWidth=boxWidth + 8; pointTop; elemCenterLeft/Right/Top/Bottom; elemEdgeLeft/Right/Top/Bottom;
还有 elemEdgeBottom > boxTotalHeight && elemCenterRight > boxWidth + 16 这些个判断条件怎么来的? 最好有个坐标系的说明
` // page let pageWidth = pageRect.width; let pageHeight = pageRect.height;
// view
let viewTop = viewRect.scrollTop;
// box
let boxWidth = boxRect.width;
let boxHeight = boxRect.height;
let boxTotalWidth = boxWidth + 8;
let boxTotalHeight = boxHeight + 8;
// elem
let elemWidth = elemRect.width;
let elemHeight = elemRect.height;
let elemTop = elemRect.top;
let elemLeft = elemRect.left;
// point
let pointTop = viewTop + elemTop;
let elemCenterLeft = elemLeft + elemWidth / 2;
let elemCenterRight = pageWidth - elemCenterLeft;
let elemCenterTop = pointTop + elemHeight / 2;
let elemCenterBottom = pageHeight - elemCenterTop;
let elemEdgeLeft = elemLeft;
let elemEdgeRight = elemCenterRight - elemWidth / 2;
let elemEdgeTop = pointTop;
let elemEdgeBottom = elemCenterBottom - elemHeight / 2;
// tl let TTop = elemEdgeTop + elemHeight + 8;
if (elemEdgeBottom > boxTotalHeight
&& elemCenterRight > boxWidth + 16){
result.supports.push('tl');
result.tl = {};
result.tl.left = elemCenterLeft - 16;
result.tl.top = TTop;
}
// tr
if (elemEdgeBottom > boxTotalHeight
&& elemCenterLeft > boxWidth + 16) {
result.supports.push('tr');
result.tr = {};
result.tr.left = elemCenterLeft - boxWidth + 16;
result.tr.top = TTop;
}
// tc
if (elemEdgeBottom > boxTotalHeight
&& elemCenterRight > boxWidth + 16
&& elemCenterLeft > boxWidth + 16) {
result.supports.push('tc');
result.tc = {};
result.tc.left = elemCenterLeft - boxWidth / 2;
result.tc.top = TTop;
}
`
能不能说明一下_getSupportOffset()这个函数的实现步骤和思路,一共12个方向看得我有点懵逼,求助大神讲解一下