【发布时间】:2020-01-10 19:44:04
【问题描述】:
我有一个盒子,一旦我们将鼠标悬停在盒子上,就会出现一个工具提示,当我进入工具提示时,工具提示仍然打开。
对于左侧的框,工具提示将向其右侧打开。
对于右侧的框,工具提示将向其左侧打开。
此方案适用于左侧框,但不适用于右侧框。
else if (e.type === 'mouseleave' && e.clientX < x.right) {
this.modelStyle = {
display: 'none'
};
}
为了处理右侧框的工具提示悬停功能,应对鼠标离开功能进行哪些更改,与处理左侧框工具提示的行为相同。
Stackblitz 链接
https://stackblitz.com/edit/angular-obzqsk?file=src/app/app.component.ts
export class AppComponent {
modelStyle: any = {
display: 'none'
};
modelClickedStyle: any = {
display: 'none'
};
modalStyleClikedFlag;
addClickEvent(e) {
let x = e.currentTarget.getBoundingClientRect();
if (e.type === 'click') {
this.modalStyleClikedFlag = true;
this.modelClickedStyle = {
top: 0 + 'px',
left: 0 + 'px',
height: 900 + 'px',
width: 90 + '%',
display: 'block'
};
}
else if (e.type === 'mouseenter') {
this.modalStyleClikedFlag = false;
if(((window.innerWidth || document.documentElement.clientWidth) - x.right) >200 ){
this.modelStyle = {
top: 0 + 'px',
left: x.right + 'px',
height: screen.height + 'px',
width: 65 +'%',
display: 'flex'
};
}else{
this.modelStyle = {
top: 0 + 'px',
right:((window.innerWidth || document.documentElement.clientWidth) x.left) + 'px',
height: screen.height + 'px',
width: 65 +'%',
display: 'flex'
};
}
}
else if (e.type === 'mouseleave' && e.clientX < x.right) {
this.modelStyle = {
display: 'none'
};
}
}
onPopEvent() {
this.modelStyle = {
display: 'none'
};
}
}
html
<div class="box1" (mouseenter)="addClickEvent($event)"
(mouseleave)="addClickEvent($event)" (click)="addClickEvent($event)">
On click
</div>
<div class="box2" (mouseenter)="addClickEvent($event)"
(mouseleave)="addClickEvent($event)" (click)="addClickEvent($event)">
On click
</div>
<fs-modal [ngStyle]="modalStyleClikedFlag ? modelClickedStyle :modelStyle"
(mouseleave)="onPopEvent($event)">
</fs-modal>
【问题讨论】:
-
@joyBlanks,该帖子中没有答案 :) 而且我已经编辑了 stackblitz 链接,如果您能提供帮助,那就太好了,谢谢
-
问题是,我使用e.clientX
-
stackblitz.com/edit/angular-yw91du 这是你要找的吗??
-
我认为是的,但您回答中唯一的问题是,如果我开箱即用,工具提示不会消失,我希望右框与我的 stackblitz 链接中的左框相同
-
好的,你也给出了 settiimeout,我认为这是正确的 :),谢谢,请发布答案,我会接受 :)
标签: javascript html css angular angular7