[100天挑战100个前端效果]第十三天---跳动的爱心(有详细的思路分析!)

先让我们来看看实现的效果

在这里插入图片描述

html代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第十三天</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="box"></div>
    <p>Love is to waster time!</p>
</body>
</html>

css代码

:root {
    --background-color: #2c3e50;
    --border-color: #7591AD;
    --text-color: #34495e;
    --color1: #EC3E27;
    --color2: #fd79a8;
    --color3: #0984e3;
    --color4: #00b894;
    --color5: #fdcb6e;
    --color6: #e056fd;
    --color7: #F97F51;
    --color8: #BDC581;
}

* {
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
}

body {
    width: 100vw;
    height: 100vh;
    background-color: var(--background-color);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
}
.box{
    position: relative;
    width: 180px;
    height: 180px;
    background-color: var(--color1);
    
    animation: animate 0.7s ease-in-out infinite;
}
.box::before,
.box::after{
    content: "";
    position: absolute;
    width: 180px;
    height: 180px;
    border-radius: 100%;
    background-color: var(--color1);
}
.box::before{
    transform: translate(-50%,0);
}
.box::after{
    transform: translate(0,-50%);    
}
p{
    margin-top: 100px;
    font-size: 40px;
    color: #fff;
}
@keyframes animate{
    0%{
        transform: scale(1) rotate(45deg);;
    }
    100%{
        transform: scale(0.8) rotate(45deg);;       
    }
}

代码思路分析和知识总结

今天主要就是用到了一个缩放的函数scale

标签作用
scale()来实现元素的缩放效果

下面让我们讲讲如何设计爱心的把!
1.设置一个box (画个正方形)
2.before after 两个内切圆
3.内切圆一个左移50%一个上移50%就出现了一个平躺的爱心
4.我们将整个box(before和after也会一起移动)向右旋转45度就得到了正的爱心,是的,爱心就支棱起来了!
5.下面,我们如何来设计动画呢?就是用到scale函数,创建keyframes,调用两个缩放就好了,不要太频繁,0,100调用就好,记得要旋转45度哦
6.在box里面animation指定keyframes即可!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值