HTML5+CSS3小实例:有趣的心形加载动画

实例:有趣的心形加载动画
技术栈:HTML+CSS
效果:

源码:
【html】

<!DOCTYPE html>
<html>
 
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
 
    <title>有趣的心形加载动画</title>
    <link rel="stylesheet" href="../css/58.css">
</head>
 
<body>
    <div class="container">
        <div class="loading">
            <span></span>
            <span></span>
            <span></span>
        </div>
        <div class="shadow"></div>
    </div>
</body>
 
</html>

【css】

*{
    /* 初始化 */
    margin: 0;
    padding: 0;
}
body{
    /* 100%窗口高度 */
    height: 100vh;
    /* 弹性布局 居中 */
    display: flex;
    justify-content: center;
    align-items: center;
}
.container{
    /* 绝对定位 */
    position: absolute;
    top: 40vh;
}
.loading{
    /* 执行动画: 动画名 时长 贝塞尔曲线 无限次播放 */
    animation: rotate 2.5s cubic-bezier(0.75,0,0.5,1) infinite;
}
.loading span{
    width: 100px;
    height: 100px;
    display: block;
    position: absolute;
    background-color: #ff8f92;
    border: 1px solid #ff8f92;
    border-radius: 100%;
}
/* 为组成心形的三个部分设置位置和动画 */
.loading span:nth-child(1){
    transform: translate(-28px,-28px);
    /* 执行动画: 动画名 时长 贝塞尔曲线 无限次播放 */
    animation: animate1 2.5s cubic-bezier(0.75,0,0.5,1) infinite;
}
.loading span:nth-child(2){
    transform: translate(28px,-28px);
    animation: animate2 2.5s cubic-bezier(0.75,0,0.5,1) infinite;
}
.loading span:nth-child(3){
    position: relative;
    border-radius: 0;
    transform: scale(0.98) rotate(-45deg);
    animation: animate3 2.5s cubic-bezier(0.75,0,0.5,1) infinite;
}
/* 阴影 */
.shadow{
    position: relative;
    width: 100px;
    height: 20px;
    background-color: #d9d9d9;
    border-radius: 50%;
    top: 50px;
    animation: shadow 2.5s cubic-bezier(0.75,0,0.5,1) infinite;
}
 
/* 定义动画 */
/* 心形 左圆 */
@keyframes animate1 {
    60%{
        transform: scale(0.4);
    }
}
/* 心形 右圆 */
@keyframes animate2 {
    40%{
        transform: scale(0.4);
    }
}
/* 心形 中间部分 */
@keyframes animate3 {
    50%{
        border-radius: 100%;
        transform: scale(0.5) rotate(-45deg);
    }
    100%{        
        transform: scale(0.98) rotate(-45deg);
    }
}
/* 心形 整体旋转 */
@keyframes rotate {
    50%{
        transform: rotate(360deg);
    }
    100%{
        transform: rotate(720deg);
    }
}
/* 阴影动画 */
@keyframes shadow {
    50%{
        background-color: #f2f2f2;
        transform: scale(0.5);
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容