【发布时间】:2020-05-09 15:52:26
【问题描述】:
我试图弄清楚这个网页上的事情是如何完成的hover effect on projects。如您所见,悬停从右到左显示并从同一方向隐藏。我正在努力实现这种效果。这就是我到目前为止所做的:
HTML
<div class="text">Simple text</div>
<div class="img"></div>
SCSS
$square-color: #FF4136;
.text{
position: absolute;
width: 100px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.img{
position: absolute;
left: 50%;
z-index: -1;
width: 75px;
height: 100%;
background-color: $square-color;
// visibility: hidden;
opacity: 0;
&.fade-in{
animation: .5s linear fadein forwards;
}
&.fade-out{
animation: .5s linear fadeout forwards alternate;
}
}
@keyframes fadein {
from{
opacity: 0;
width: 0px;
}
to{
opacity: 1;
width: 75px;
}
}
@keyframes fadeout{
from{
opacity: 1;
width: 75px;
transform-origin: left;
}
to{
opacity: 0;
width: 0px;
}
}
JS
const txt = document.querySelector('.text');
const img = document.querySelector('.img');
txt.addEventListener('mouseover', function() {
img.classList.remove('fade-out');
img.classList.add('fade-in');
})
txt.addEventListener('mouseout', function(){
img.classList.remove('fade-in');
img.classList.add('fade-out');
})
感谢您的帮助和任何提示!
【问题讨论】:
-
不,它没有......检查我展示的示例的悬停效果:/