如何在 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模板网!
在 Angular 2/Typescript 中使用 IScrollUse IScroll in Angular 2 / Typescript(在 Angular 2/Typescript 中使用 IScroll)
Anime.js 在 Ionic 3 项目中不起作用anime.js not working in Ionic 3 project(Anime.js 在 Ionic 3 项目中不起作用)
Ionic 3 - 使用异步数据更新 ObservableIonic 3 - Update Observable with Asynchronous Data(Ionic 3 - 使用异步数据更新 Observable)
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指In Ionic 2, how do I create a custom directive that uses Ionic components?(在 Ionic 2 中,如何创建使用 Ionic 组件的自定义指令?)
将 ViewChild 用于动态元素 - Angular 2 &离子2Use ViewChild for dynamic elements - Angular 2 amp; ionic 2(将 ViewChild 用于动态元素 - Angular 2 amp;离子2)