【发布时间】:2019-12-05 17:35:35
【问题描述】:
我正在运行 Angular 应用程序,我计算元素的宽度并将其存储在变量 finalposition 下,我想向左 (finalposition)px 移动。我希望仅在将鼠标悬停在元素上时应用此样式属性。如何做到这一点?
component.ts
ngAfterViewChecked(): void {
this.finalposition = document.getElementById('spandiv').offsetWidth;
}
component.html
<input id="inputCustome" type="text">
<p id="spandiv">xyzkskssss</p>
component.css
#inputCustomer {
text-align: center;
position: relative;
bottom: 7px;
left: 2px;
}
#spandiv {
position: absolute;
right:145px;
top: 40px;
background-color: #6B6664;
padding: 5px;
color:white;
font-weight: normal;
display: block;
opacity:0;
overflow: hidden;
}
#inputCustomer:hover + #spandiv {
position: absolute;
left: var(--finalPosition*2)+ "px"; // this value is not getting picked up
top:40px;
display: inline;
opacity:1;
}
【问题讨论】:
-
嗨,如何仅在悬停时应用 ngStyle
-
你试过解决方案了吗?
标签: javascript html css angular typescript