当我将鼠标移到文本框“ services-right”上时,将触发动画,并且文本将向右移动。当我将光标移动到“ about-us--services__button”按钮时,文本将返回其左侧的位置。
如何使文本在光标位于按钮上时不会向左移动,而当鼠标光标位于文本和按钮块之外时又回到左侧位置?
(截断运行代码以了解我的意思)
当我将鼠标悬停在按钮上时,文本不应向左移动,如果在按钮和文本区域之外,则应向左移动
.servicies-right {
margin-top: 70px;
}
.about-us--services__text {
position: absolute;
z-index: 1;
right: 34%;
top: 180px;
transition: 0.6s ease-in;
}
.about-us--services__text:hover {
transform: translateX(10%);
}
.about-us--services__title {
float: right;
font-weight: 700;
}
.about-us--services__button {
display: inline-block;
margin-left: 30px;
padding: 25px 50px 25px 50px;
background: none;
color: blue;
font-weight: bold;
position: relative;
transition: color 0.25s ease;
border: 3px solid #383736;
cursor: pointer;
}
.about-us--services__button:after {
position: absolute;
content: '';
top: 0;
left: 0;
width: 0;
height: 100%;
background-color: #383736;
transform-origin: left;
transition: width 0.25s ease;
z-index: -1;
}
.about-us--services__button:hover:after {
width: 100%;
}
.about-us--services__button-title {
position: absolute;
right: 40px;
bottom: 12px;
}
img {
max-width: 150px;
min-width: 150px;
min-height: 100px;
max-height: 100px;
}
.servicies-right {
float: right;
}
<div class="servicies-right">
<div class="about-us--services__text">
<span class="about-us--services__title-desctription">Test title text first</span>
<br>
<span class="about-us--services__title">Test subtitle</span>
</div>
<img src="https://24tv.ua/resources/photos/news/201805/961055.jpg" alt="test" class="move-img">
<button class="about-us--services__button"><span class="about-us--services__button-title">Abcdfeghrf</span></button>
</div>
答案 0 :(得分:1)
以0秒的速度向元素添加另一个transition
,因此“输入”动画的出现时间为0.6秒,退出时间为0秒:
.servicies-right {
margin-top: 70px;
}
.about-us--services__text {
position: absolute;
z-index: 1;
right: 34%;
top: 180px;
transition: 0.6s ease-in;
}
.servicies-right:hover .about-us--services__text {
transform: translateX(10%);
}
.about-us--services__title {
float: right;
font-weight: 700;
}
.about-us--services__button {
display: inline-block;
margin-left: 30px;
padding: 25px 50px 25px 50px;
background: none;
color: blue;
font-weight: bold;
position: relative;
transition: color 0.25s ease;
border: 3px solid #383736;
cursor: pointer;
}
.about-us--services__button:after {
position: absolute;
content: '';
top: 0;
left: 0;
width: 0;
height: 100%;
background-color: #383736;
transform-origin: left;
transition: width 0.25s ease;
z-index: -1;
}
.about-us--services__button:hover:after {
width: 100%;
}
.about-us--services__button-title {
position: absolute;
right: 40px;
bottom: 12px;
}
img {
max-width: 150px;
min-width: 150px;
min-height: 100px;
max-height: 100px;
}
.servicies-right {
float: right;
}
<div class="servicies-right">
<div class="about-us--services__text">
<span class="about-us--services__title-desctription">Test title text first</span>
<br>
<span class="about-us--services__title">Test subtitle</span>
</div>
<img src="https://24tv.ua/resources/photos/news/201805/961055.jpg" alt="test" class="move-img">
<button class="about-us--services__button"><span class="about-us--services__button-title">Abcdfeghrf</span></button>
</div>