如何在Ionic中定位一个popover 2 [英] How to position a popover in Ionic 2

查看:219
本文介绍了如何在Ionic中定位一个popover 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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.

推荐答案

查看代码,似乎没有弹出窗口位置的选项。但是,当用户点击某些东西打开弹出窗口时,可以通过click事件定位它。我们也可以将这些知识用于手动定位:

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 未给出,那么通常的定位算法用于该值。

  • You can set the value for top, left, or both.
  • The values must be given in pixels, as numbers.
  • If 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.

这篇关于如何在Ionic中定位一个popover 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆