CSS是前端开发者的必备技能之一,它可以让我们设计出像夜空繁星般美丽的网页。其中,CSS动画也是网页设计中不可或缺的一部分。好看的加载动画能让用户在等待页面加载时感到愉悦,退出本网页的概率也会降低。下面将介绍几种好看的CSS加载动画。
.loader {display: inline-block;position: relative;width: 80px;height: 80px;}.loader div {position: absolute;top: 33px;width: 13px;height: 13px;border-radius: 50%;background: #fff;animation-timing-function: cubic-bezier(0, 1, 1, 0);}.loader div:nth-child(1) {left: 8px;animation: lds-ellipsis1 0.6s infinite;}.loader div:nth-child(2) {left: 8px;animation: lds-ellipsis2 0.6s infinite;}.loader div:nth-child(3) {left: 32px;animation: lds-ellipsis2 0.6s infinite;}.loader div:nth-child(4) {left: 56px;animation: lds-ellipsis3 0.6s infinite;}@keyframes lds-ellipsis1 {0% {transform: scale(0);}100% {transform: scale(1);}}@keyframes lds-ellipsis3 {0% {transform: scale(1);}100% {transform: scale(0);}}@keyframes lds-ellipsis2 {0% {transform: translate(0, 0);}100% {transform: translate(24px, 0);}}
上面的代码显示一个简单的四点动画加载。动画中心右侧有一个未填充的点,它会在三个填充点之间循环运动。
.loading {height: 36px;width: 80px;text-align: center;font-size: 10px;}.loading >div {height: 100%;width: 8px;margin-right: 4px;display: inline-block;animation: loading 1.2s infinite;}.loading .bar1 {background-color: #3498db;}.loading .bar2 {background-color: #e74c3c;animation-delay: -1.1s;}.loading .bar3 {background-color: #f1c40f;animation-delay: -1s;}.loading .bar4 {background-color: #2ecc71;animation-delay: -0.9s;}@keyframes loading {0%, 100% {transform: scale(0);}50% {transform: scale(1);}}
此代码使用了一个有趣的巧思,动态地填充色块。每个块都有不同的颜色和动画延迟,它们以定时循环方式使您的加载状态显得更加逼真和动态。
总之,CSS加载动画不仅为用户带来了愉悦的加载体验,而且也为开发人员提供了显示加载过程的简单方法。使用上面的代码,开发人员可以自己制作出令人愉悦的加载体验。