【发布时间】:2018-09-09 09:09:08
【问题描述】:
我有 for 循环在页面中显示我的所有产品..现在我希望当用户将鼠标悬停在产品上时,它的相关详细信息显示在 div 中,效果我确实喜欢这样做,但我认为这不是正确的方式,不透明度也不起作用我的代码。
...我的目的是细节(在我的代码 div 中带有 calas "c-reveal")应该在鼠标进入产品时有效显示,当用户离开细节或父母时细节将消失
<ul class="home-product">
<li *ngFor="let product of products; let i = index " [attr.data-index]="i" (mouseenter)="show($event)"
(mouseleave)="leavep($event)">
<div class="card product-card">
<div class="card-content">
{{ product.title }}
</div>
<div class="c-reveal" (mouseleave)="leave($event)">
this will show when parent hoverd
</div>
</div>
</li>
</ul>
css:
.c-reveal {
position: absolute;
background: white;
z-index: 3;
margin-left: 247px;
bottom: 155px;
width: 225px;
display: none;
opacity: 0;
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, .2);
border-radius: 2px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
box-shadow: 0 5px 10px rgba(0, 0, 0, .2);
transition: all 1s ease-in-out;
}
.show{
opacity: 1;
display: block;
}
component.ts:
show(e) {
let card = e.srcElement.children[0].children[2];
card.classList.add('show');
}
leavep(e) {
console.log(e);
let card = e.srcElement.children[0].children[2];
card.classList.remove('show');
}
leave(e) {
let target = e.target;
target.classList.remove('show');
}
【问题讨论】:
-
您应该为此使用 Angular 的状态动画。
标签: javascript css angular angular5