Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
如何使用CSS和混色模式实现loader动画效果(附代码)_创想鸟

如何使用CSS和混色模式实现loader动画效果(附代码)

本篇文章给大家带来的内容是关于如何使用css和混色模式实现loader动画效果(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

效果预览

831752590-5b7caf8097660_articlex.gif

源代码下载

https://github.com/comehope/front-end-daily-challenges

代码解读

定义 dom,只有 1 个元素:

居中显示:

立即学习“前端免费学习笔记(深入)”;

body {    margin: 0;    height: 100vh;    display: flex;    align-items: center;    justify-content: center;    background-color: lightyellow;}

定义容器尺寸:

.loader {    width: 30em;    height: 3em;    font-size: 10px;}

用伪元素画出2个圆角矩形,各占容器的一半宽,放置在容器的左右两端,分别上色:

.loader {    position: relative;}.loader::before,.loader::after {    content: '';    position: absolute;    width: 50%;    height: inherit;    border-radius: 1em;}.loader::before {    left: 0;    background-color: dodgerblue;}.loader::after {    right: 0;    background-color: hotpink;}

为圆角矩形增加 ‘loading’ 文本:

.loader::before,.loader::after {    content: 'loading';    font-size: 2.5em;    color: white;    text-align: center;    line-height: 1em;}

增加动画效果:

.loader::before,.loader::after {    animation: 5s move ease-in-out infinite;}@keyframes move {    50% {        transform: translateX(100%);    }}

为两个圆角矩形分别设置运动方向变量,使它们相对移动:

.loader::before {    --direction: 1;}.loader::after {    --direction: -1;}@keyframes move {    50% {        transform: translateX(calc(100% * var(--direction)));    }}

最后,设置混色模式,使两个矩形相交的部分不是覆盖而是使颜色重叠:

.loader::before,.loader::after {    mix-blend-mode: multiply;}

大功告成!

相关推荐:

如何用CSS实现一只带帽子的大熊猫(附代码)

如何使用纯CSS实现切换按钮时背景的悬停动画效果

以上就是如何使用CSS和混色模式实现loader动画效果(附代码)的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1611276.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
如何使用CSS实现渐变色动画边框的效果(附代码)
上一篇 2025年12月24日 02:10:27
css如何自定义radio单选框样式 ?(代码实现)
下一篇 2025年12月24日 02:10:46

相关推荐

发表回复

登录后才能评论
关注微信