Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

javascript - 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.

{
 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.

Reproducible 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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try to use your variable with getBoundingClientRect, little example, change:

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

to

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...