在Material-UI中,为什么要将这个变量设置为自身
In Material-UI why do they set this variable to itself?
不明白为什么Material-UI会为它的Popover设置一个等于它自己的变量
下面是检查返回前两个if块的代码片段:
设置t.vertical = t.vertical;
的目的是什么?
getPositions(anchor, target) {
const a = {...anchor};
const t = {...target};
const positions = {
x: ['left', 'right'].filter((p) => p !== t.horizontal),
y: ['top', 'bottom'].filter((p) => p !== t.vertical),
};
const overlap = {
x: this.getOverlapMode(a.horizontal, t.horizontal, 'middle'),
y: this.getOverlapMode(a.vertical, t.vertical, 'center'),
};
positions.x.splice(overlap.x === 'auto' ? 0 : 1, 0, 'middle');
positions.y.splice(overlap.y === 'auto' ? 0 : 1, 0, 'center');
if (overlap.y !== 'auto') {
a.vertical = a.vertical === 'top' ? 'bottom' : 'top';
if (overlap.y === 'inclusive') {
t.vertical = t.vertical; // HERE
}
}
if (overlap.x !== 'auto') {
a.horizontal = a.horizontal === 'left' ? 'right' : 'left';
if (overlap.y === 'inclusive') {
t.horizontal = t.horizontal; // HERE
}
}
return {
positions: positions,
anchorPos: a,
};
}
好像是打错了。
getOverlapMode(anchor, target, median) {
if ([anchor, target].indexOf(median) >= 0) return 'auto';
if (anchor === target) return 'inclusive';
return 'exclusive';
}
看起来'inclusive'的重叠意味着锚点和目标是相同的。我最可能的猜测是,最初的贡献者chrismcv打算这样做:
if (overlap.y !== 'auto') {
a.vertical = a.vertical === 'top' ? 'bottom' : 'top';
if (overlap.y === 'inclusive') {
t.vertical = a.vertical; // update target to match anchor
}
}
if (overlap.x !== 'auto') {
a.horizontal = a.horizontal === 'left' ? 'right' : 'left';
if (overlap.y === 'inclusive') {
t.horizontal = a.horizontal; // update target to match anchor
}
}
锚点刚刚更新,所以如果包含重叠,这将使锚点和目标保持同步。
相关文章:
- 如何在Bootstrap Modal中为动态点击生成的变量设置jade属性
- Javascript使用变量设置属性
- 敲除js变量设置类似于调用函数
- 使用输入变量设置元素的值
- 为什么我们将控制器变量设置为等于“0”;这个“;在角度上
- 将外部控制器的范围变量设置为角度
- 谷歌地图标记在通过变量设置标记和经度时不保持不变
- 尝试在 jquery ajax 帖子中将变量设置为URL 的一部分
- 如果循环中至少有一个元素返回 false,如何将变量设置为 false
- 如何将宽度和高度变量设置为浏览器窗口的宽度和高度
- 如何将变量设置为外部内容
- 需要将变量设置为特定的数字范围
- 执行批处理文件的Javascript,该文件包含基于每个会话的环境变量设置
- 如何在jquery中基于变量设置某个东西的宽度
- 将变量设置为等于本地JSON文件
- 根据Angular中的单独变量设置下拉默认值
- 如何使用JavaScript变量设置函数集css宽度
- 如何为一个javascript变量设置give多个值
- 如何将javascript变量设置为php变量并将其存储在数据库中
- 如何在javascript中为变量设置一行setter