css3 来回跳

学习下css3 animation 与 transform

keyframe是动画无限执行  ease是圆滑  infinite是无限次

 

<!DOCTYPE html>
<html >

<head>
    <meta charset="UTF-8">
    <title>点扩散</title>
    <style>
        #circle
        {
            width:4px;
            height:4px;
            background-color:#ffffff;        
            border-radius:50%;
            border:6px solid blue;    
            position: relative;
            margin:100px;
        }
        #circle p,#circle span
        {
            position: absolute;
            width:4px;
            height:4px;
            border-radius:50%;
            
            box-shadow: 0px 0px 1px #009FD9;
            animation: halo 1.5s infinite;
            margin:0px;
            padding:0px;
        }
        
        #circle span
        {
            animation-delay:0.1s;
        }
        
        #circle #p1
        {
            animation-delay:0.2s;
        }
        
        
        #circle #span1
        {
            animation-delay:0.8s;
        }
        
        
        @keyframes halo
        {
            10% { transform:scale(1)}
            100% { transform:scale(8)}
        }
        
        #jump
        {
            width:4px;
            height:4px;
            background-color:#ffffff;        
            border-radius:50%;
            border:6px solid blue;    
            position: relative;
            margin-left:10px;
            animation:jumpDiv 1.5s ease infinite ;
            float:left
        }
        
        @keyframes jumpDiv
        {
            0%,100% { transform:translateY(0px)}
            
            50% { transform:translateY(30px)}
            
        }
        
        #stand
        {
            width:4px;
            height:4px;
            background-color:#ffffff;        
            border-radius:50%;
            border:6px solid blue;    
            position: relative;
            margin-left:10px;
            float:left;
            
            
        }

    </style>

</head>

<body>

    <div id="circle">
        <p></p>
        <span></span>
        <p id="p1"></p>
        <span id="span1"></span>
        
    </div>
    <div id="stand">
        
        
    </div>
    <div id="jump"></div>

</body>

</html>

 

 

10% { transform:translateY(10px)}
            20% { transform:translateY(20px)}
            40% { transform:translateY(30px)}
            60% { transform:translateY(40px)}
            80% { transform:translateY(50px)}
            100% { transform:translateY(60px)} 本来是这样写的,可是只能一个方向跳动,后来在网上找了资料,就是下面的,也不行,后来想想一共是30px距离,那么 50%就应该是最高了,0% 和100%就是 0了,这样就对了

 

下面是网上的

<html><head>
    <meta charset="UTF-8">
    <meta name="google" value="notranslate">


    <title>WEB骇客DEMO - CSS animation 两种动画同时进行</title>
    
    
    <link rel="stylesheet" href="reset.css">

    
    <style>
      .element {
  height: 200px;
  width: 200px;
  background-color: red;
  -webkit-animation: pulse 3s ease infinite alternate,  nudge 5s linear infinite alternate;
          animation: pulse 3s ease infinite alternate,  nudge 5s linear infinite alternate;
  border-radius: 100%;
}

@-webkit-keyframes pulse {
  0%, 100% {
    background-color: red;
  }
  50% {
    background-color: orange;
  }
}

@keyframes pulse {
  0%, 100% {
    background-color: red;
  }
  50% {
    background-color: orange;
  }
}
@-webkit-keyframes nudge {
  0%, 100% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  50% {
    -webkit-transform: translate(150px, 0);
            transform: translate(150px, 0);
  }
  80% {
    -webkit-transform: translate(-150px, 0);
            transform: translate(-150px, 0);
  }
}
@keyframes nudge {
  0%, 100% {
    -webkit-transform: translate(0, 0);
            transform: translate(0, 0);
  }
  50% {
    -webkit-transform: translate(150px, 0);
            transform: translate(150px, 0);
  }
  80% {
    -webkit-transform: translate(-150px, 0);
            transform: translate(-150px, 0);
  }
}
html, body {
  height: 100%;
}

body {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
      -ms-flex-pack: center;
          justify-content: center;
}   

 </style>  
  </head>

  <body>
    <div class="element"></div>    
</body></html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值