html - 仅对文本产生窗帘效果 - 文本从中间到外边缘显示
问题描述
我正在尝试在某些文本上创建窗帘效果。我希望首先隐藏文本,然后从文本中间到外边缘进行动画显示。即使有奇数个字母,我也希望它能够工作。换句话说,分解字符串是行不通的。如果字符串中只有一个大字符,我希望它从字符中心显示到字符的外边缘。我不想要背景上的窗帘效果,因为我还不知道我想要什么样的背景。我只希望它在文本上。
这是我到目前为止所拥有的:
HTML
<div class="container">
<div class="my-name">The Incredible Houdini</div>
</div>
CSS
body {
margin: 0;
}
.container {
position: relative;
font-size: 3vh;
width: 100%;
height: 100vh;
background: lightblue;
}
.my-name {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
font-size: 2em;
font-weight: bold;
color: darkblue;
width: 0;
overflow: hidden;
white-space: nowrap;
animation: showName 5s linear 3s forwards;
}
@keyframes showName {
from {
width: 0;
}
to {
width: 15ch;
}
}
溢出:隐藏和从 0 到 100 的宽度给了我我想要的,因为单个字符逐渐被显示而不是像打字机一样弹出。问题是它从左到右生成。有什么办法可以开始将宽度从中间扩展到外边缘?
解决方案
首先,您需要一个关键帧来调整auto
宽度,这是您无法做到的。我建议重新考虑你的方法。
我会为剪辑路径设置动画
body {
margin: 0;
}
.container {
position: relative;
font-size: 25vh;
width: 100%;
height: 100vh;
background: lightblue;
display:flex;
justify-content:center;
align-items:center;
}
.my-name {
font-weight: bold;
color: white;
overflow: hidden;
padding: .25em;
background: rebeccapurple;
clip-path: inset(0 100% 0 100%);
animation: showName 5s linear forwards;
}
@keyframes showName {
0% {
clip-path: inset(0 100% 0 100%);
}
100% {
clip-path: inset(0);
}
}
<div class="container">
<div class="my-name">The Incredible Houdini</div>
</div>
推荐阅读
- sql - SQL - 列的反转部分
- c# - NAudio 记录和保存麦克风输入和扬声器输出
- c++ - C++ 何时在运算符重载函数前使用 &
- python - DRF 更改默认视图集的 lookup_field 以进行自定义操作
- web - 无法访问 Power Designer Web 门户
- javascript - Javascript警报根本不显示
- typo3 - TYPO3 - 页面渲染后的钩子/信号
- database - 如何在 laravel 中使用 Group by 查询?
- php - 不能将字符串偏移量用作 addressfield_widget_process() 中的数组
- python - 为什么在新测试图像上运行良好的卷积神经网络模型在视频流上失败?