我在如上所述的“弹出”菜单中使用了Material-ui(v 4.9.5)Popper
。 anchorElement
是左侧选择的ListItem
。我希望Popper
与主菜单的顶部平齐。但是它看起来短了5px。
[如果我查看Chrome开发工具,则会看到以下内容,而5px
参数中的translate3d
值就是问题。如果我在开发工具中将值更改为0px
,问题就解决了。
我的问题是如何通过代码实现这一点。我已经尝试使用modifiers
作为底层popper.js的以下内容,并且它无所事事。
<Popper
modifiers={{
offset: {
enabled: true,
offset: '-5, 0'
},
}}
className={globalMenuStyle.popperStyle}
placement="right-end"
open={isPopoverOpen}
onClose={handleHidingGlobalMenu}
anchorEl={anchorElement}>
{popoverMenuItems}
</Popper>
甚至更陌生的是,如果我尝试并尝试类似的操作,然后尝试将modifiers
的x轴移动,它会沿x轴移动。 为什么x轴不起作用,而y轴不起作用?
modifiers={{
offset: {
enabled: true,
offset: '0, 50'
},
}}
使用popperOptions
属性为popper.js实例提供选项obj,如下所示:
popperOptions