Pulsing Heart CSS animation

前端 未结 7 1058
小蘑菇
小蘑菇 2020-12-12 12:34

I`m working on an animated heart only with CSS.

I want it to pulse 2 times, take a small break, and then repeat it again.

What I have now:

sm         


        
7条回答
  •  有刺的猬
    2020-12-12 12:54

    body{
      margin: 0;
      padding: 0;
      background: #1f1f1f;
    }
    
    body:before
    {
      position: absolute;
      content: '';
      left: 50%;
      width: 50%;
      height: 100%;
      background: rgba(0,0,0,.2);
    
    }
    
    .center
    {
      position: absolute;
      top:50%;
      left: 50%;
      background: #1f1f1f;
      transform: translate(-50%,-50%);
      padding: 100px;
      border: 5px solid white;
      border-radius: 100%;
      box-shadow:20px 20px 45px rgba(0,0,0,.4);
      z-index: 1;
      overflow: hidden;
    }
    .heart
    {
      position: relative;
      width: 100px;
      height: 100px;
      background:#ff0036;
      transform: rotate(45deg) translate(10px,10px);
      animation: ani 1s linear infinite;
    }
    .heart:before
    {
      content: '';
      width: 100%;
      height: 100%;
      background: #ff0036;
      position: absolute;
      top:-50%;
      left:0;
      border-radius: 50%;
    }
    .heart:after
    {
      content:'';
      width: 100%;
      height: 100%;
      background: #ff0036;
      position: absolute;
      bottom:0;
      right:50%;
      border-radius: 50%;
    }
    .center:before
    {
      content: '';
      position: absolute;
      top:0;
      left:-50%;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,.3);
    }
    
    @keyframes ani{
      0%{
        transform: rotate(45deg) translate(10px,10px) scale(1);
      }
      25%{
        transform: rotate(45deg) translate(10px,10px) scale(1);
      }
      30%{
        transform: rotate(45deg) translate(10px,10px) scale(1.4);
      }
      50%{
        transform: rotate(45deg) translate(10px,10px) scale(1.2);
      }
      70%{
        transform: rotate(45deg) translate(10px,10px) scale(1.4);
      }
      90%{
        transform: rotate(45deg) translate(10px,10px) scale(1);
      }
      100%{
        transform: rotate(45deg) translate(10px,10px) scale(1);
      }
    }
    
    
      
        
        HeartBeat Animation
        
      
      
        

    Output

    for more: Heart Beating Animation

提交回复
热议问题