简体   繁体   English

根据框 position 打开弹出模式

[英]To open popup modal based on the box position

I want the popup modal opening where the box is.For the top 2 boxes placed the modal opens correctly, I was trying for the last 2 boxes placed at bottom as well.我想要盒子所在的弹出模式打开。对于放置的顶部 2 个盒子,模态打开正确,我也在尝试放置在底部的最后 2 个盒子。

{
 top: 0 + 'px'+ this.el.nativeElement.offsetTop + 'px',
 right: ((window.innerWidth || document.documentElement.clientWidth) - x.left) - 20 + 'px',
 height: 'auto',
 width: 58 + '%',
 display: 'flex'
};

I tried adding offsetop but then the modal is placed at the bottom.我尝试添加 offsetop 但随后模态被放置在底部。

Reproducible stackblitz https://stackblitz.com/edit/angular-pbxxgr?file=src/app/app.component.scss可重现的 stackblitz https://stackblitz.com/edit/angular-pbxxgr?file=src/app/app.component.scss

Without adding any top value(works for top 2 boxes) (Same expectation is for the bottom 2 boxes) https://stackblitz.com/edit/angular-ufwotn?file=src/app/app.component.ts不添加任何顶部值(适用于顶部 2 个框) (对于底部 2 个框的期望相同) https://stackblitz.com/edit/angular-ufwotn?file=src/app/app.component.ts

I want similar kind of behaviour as happening for 1st 2 boxes, whenever I hover for the bottom 2 boxes the modal is opening from top near to the 1st 2 boxes, whereas the expectation is till wherever I have scrolled then from there top of the screen the modal should open我想要与第一个 2 个盒子发生的类似行为,每当我为底部 2 个盒子做 hover 时,模式从顶部靠近第一个 2 个盒子打开,而期望是直到我从那里滚动到屏幕顶部模态应该打开

try to use your variable with getBoundingClientRect, little example, change:尝试将您的变量与 getBoundingClientRect 一起使用,小例子,更改:

this.modelstyle {
    top: 0 + px;
  ...here other your code...
}

to

this.modelStyle {
   top: x.top + window.scrollY + 'px',
...here other your code...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM