Popover: How can be show exactly where clicked in the screen?


#1

Hi,

I’ve an image, covering the whole viewport, and want to show a popup exactly when the user clicked the image, and the popup is showing in the top-left corner of the image, so it seems that it get the coordinates from the element that was clicked and not the actual coordinates of the click.

Thanks in advance.


#2

Try with clientY and clientX to change the coordinates.

presentOptionsPopover(ev, item) {
    const popover = this.popoverCtrl.create(PopoverOptionsComponent, {
      deleteItem: () => {
        this.deleteItem(item);
      },
      lng: this.lng,
      item: item
    });
    let evt = {
      target: {
        getBoundingClientRect: () => {
          return {
            top: ev.clientY,
            left: ev.clientX
          };
        }
      }
    };
    popover.present({ ev: evt });
  }