I have an implementation of hover(mouseenter), click, mouseleave, which shows and hide the popup modal component whenever the target element is hovered.
But the issue is the popup modal component opens a bit far away from the hovered element that is due to the top,left
position I am giving.
How can I correctly position this modal component and is it possible to place the popup component just by the side of the mouse cursor instead of the popup being by the side of the hovered element?
(And also the distance of the popup component varies when I hover over the element).
Maybe CSS :after
can be a solution?
Minimum Reproducible example
https://stackblitz.com/edit/angular-34rr1t?file=src/app/app.component.html
TS file for handling opening and closing of popup modal
modalShow = false;
modalleft;
modaltop;
addClickEvent(e,name) {
if (e.type === 'click') {
this.modalShow= true;
}
else if (e.type === 'mouseenter') {
this.modalleft = e.clientX
this.modaltop = e.clientY
this.closeModal("room");
this.modalShow= true;
}
else if (e.type === 'mouseleave') {
this.closeModal('room');
this.modalShow= false;
}
}
closeModal(modalType: string) {
this.modal[modalType].active = false;
}
HTML for handling opening and closing of popup modal
<div class="fs-heatmap-wrapper__content__box"
*ngFor="let existingZone of floor.droppeditem"
(mouseenter)="addClickEvent($event,floor.name)"
(mouseleave)="addClickEvent($event,floor.name)"
(click)="addClickEvent($event,floor.name)">
</div>
<fs-modal *ngIf="!modalShow"
[ngStyle]="{'top.px': modalleft,
'left.px':modaltop ,
'position':'absolute'}"
(onCloseModal)="closeModal('room')">
</fs-modal>
HTML fs-modal
<div class="modal">
<div class="modal__body">
</div>
</div>
CSS fs-modal
.modal {
background: rgba(0, 0, 0, 0.5);
max-height: 100%;
overflow-y: scroll;
z-index: 9999999;
&__body {
pointer-events: all;
padding: 50px;
background: #ffffff;
box-shadow: 4px 45px 23px -6px rgba(0, 0, 0, 0.4);
margin: 2% 0;
height: auto;
*min-height: 1200px;
}