如何在 Ionic 2 中手动定位弹出框?
How do I manually position a popover in Ionic 2?
我无法在 css 类中设置位置,因为弹出框控制器使用内联样式设置位置.
I can't set the position in a css class, since the popover controller sets the position with an inline style.
查看代码,弹出框的位置似乎没有选项.但是,当由于用户点击某物而打开弹出框时,它可以通过点击事件定位.我们也可以将这些知识用于手动定位:
Looking through the code, there doesn't seem to be an option for the popover's position. However, when opening the popover as a result of the user tapping something, it can be positioned by the click event. We can use that knowledge for manual positioning as well:
let pop = this.popoverCtrl.create(MyPopover);
let ev = {
target : {
getBoundingClientRect : () => {
return {
top: 100
};
}
}
};
pop.present({ev});
需要注意的几点:
top
、left
或两者的值.top
或 left
没有给出,那么通常的定位算法将用于该值.top
, left
, or both.top
or left
is not given, then the usual positioning algorithm is used for that value.我很高兴知道是否有更好的方法,但到目前为止这是我能想到的最好方法.
I'd be happy to know if there's a better way, but so far this is the best I could come up with.
这当然适用于 Ionic2 和 3,很高兴有人确认它是否也适用于 Ionic4!
This certainly works in Ionic2 and 3, happy to have someone confirm if it works in Ionic4 as well!
这篇关于如何在 Ionic 2 中定位弹出框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!