[css]利用css动画制作心跳

127 阅读1分钟

html:

<main>
    <div class="heart"></div>
</main>

 css:

*{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body{
            width: 100vw;
            height: 50vh;
            background: #80a0ff;
        }
        .heart {
            margin: 300px auto 0;
            width: 200px;
            height: 200px;
            background: #e74c3c;
            transform: rotate(45deg);
            position: relative;
            animation-name: heart;
            animation-duration: 1s;
            animation-iteration-count: 100;
        }
    
        .heart::before {
            content: '';
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: #e74c3c;
            position: absolute;
            transform: translate(-50%, 0px);
        }
    
        .heart::after {
            content: '';
            width: 200px;
            height: 200px;
            border-radius: 50%;
            background: #e74c3c;
            position: absolute;
            transform: translate(0%, -50%);
        }
    
        @keyframes heart {
            from {
                transform: scale(.3) rotate(45deg);
            }
    
            to {
                transform: scale(1) rotate(45deg);
            }
        }