我正在尝试为类".popUpWord"
的文字添加动画效果。在鼠标悬停时,我想要进行颜色动画,使文本颜色从左到右渐变。
<span class="popUpWord">hello</span>
我希望做的与这个类似 - 从左到右填充动画,但我想要它从左到右填充停止,而不是重复填充。
请问这是否可以通过CSS实现?
我正在尝试为类".popUpWord"
的文字添加动画效果。在鼠标悬停时,我想要进行颜色动画,使文本颜色从左到右渐变。
<span class="popUpWord">hello</span>
当鼠标悬停时,添加一个外部div并添加mix-blend-mode: multiply;
.popUpWord {
text-transform: uppercase;
font: bold 26vmax/.8 Open Sans, Impact;
background: black;
display: table;
color: white;
}
.outPop:hover {
margin: auto;
background: linear-gradient( crimson , crimson) white no-repeat 0 0;
background-size: 0 100%;
animation: stripes 2s linear 1 forwards;
}
.outPop:hover .popUpWord{
mix-blend-mode: multiply;
}
@keyframes stripes {
to {
background-size:100% 100%;
}
}
body {
float:left;
height: 100%;
background: black;
}
<div class="outPop">
<div class="popUpWord">
Text
</div>
</div>
:hover
上删除动画。 - jafarbtechjustify-content: start
定位文本,并且overflow:hidden
带有0的宽度。.wrapper {
position: relative;
width: 400px;
font-family: 'Arial', sans-serif;
font-size: 24px;
background: beige
}
.fill-wrapper {
width: 300px;
}
.fill-text {
display: grid;
justify-content: start;
position: absolute;
top: 0;
left: 0;
overflow: hidden;
word-break: keep-all;
width: 0;
color: red;
transition: 0.5s width ease-in-out;
}
.text {
width: 150px;
color: black;
}
.wrapper:hover .fill-text {
width: 150px;
transition: 0.5s width ease-in-out;
}
<div class="wrapper">
<div class="fill-text">
<div class="fill-wrapper">
My Text
</div>
</div>
<div class="text">
My Text
</div>
</div>
我们可以使用新功能background-clip:text
。首先,我们将color
设置为透明(这将使我们的背景颜色可见),然后将背景设置为渐变,其中两种颜色各占50%(第一种颜色是我们要过渡到的颜色,第二种颜色是基础颜色)。接下来,我们将background-size
设置为200%,将background-position
设置为100%(这将仅显示我们的第二种颜色)。最后,我们使用background-position:0;
添加悬停效果。
h1{
color: transparent;
background-image: linear-gradient(90deg, yellow 50%, green 50%);
background-position:100%;
background-size:200% 100%;
background-clip:text;
-webkit-background-clip:text;
transition: background-position 1s ease;
}
h1:hover{
background-position:0;
}
<h1>Some text</h1>
背景位置。