web前端:原生css球体弹跳效果,animation动画keyframes应用,指定停止动画animation-play-state:paused

1.less

* {
    margin: 0;
    padding: 0;
    #wrap {
        position: absolute;
        width: 600px;
        height: 600px;
        background: url(../img/my-logo-2.png) repeat;
        background-size: 50px;
        border: 1px solid #000000;
        border-radius: 50%;
        top: 50%;
        left: 50%;
        margin-left: -300px;
        margin-top: -300px;
        
        &:hover #wrap-inner{
            //animation-play-state:动画执行的运行/暂停,默认值running,pause暂停
            animation-play-state: paused;
        }
        
        #wrap-inner {
            position: absolute;
            width: 300px;
            height: 300px;
            background: tomato;
            border: 2px solid white;
            border-radius: 50%;
            box-shadow: 2px 2px 5px tomato;
            font: 30px/300px "微软雅黑";
            text-align: center;
            color: white;
            top: 50%;
            left: 50%;
            margin-left: -150px;
            margin-top: -150px;
            animation-name: rotated;
            animation-duration: 1.5s;
            //animation-timing-function: linear;
            animation-timing-function: cubic-bezier(.12,1.36,.65,-0.28);
            //direction:normal(from→to)reverse反转(to→from)、alternate(from→to→from...循环)/alternate-reverse
            animation-direction: alternate;
            animation-iteration-count: 6;
            //延迟为外部动画
            animation-delay: 1s;
            /*元素在动画外的状态: from之前to之后
              1. backwards与from一致=动画开始的动作,结束回归原位
              2. forwards与to一致=动画结束的动作,结束不回归原位
              3. both=动画开始/结束的动作,开始/结束不回归原位
            */
            //animation-fill-mode: backwards;
            //animation-fill-mode: forwards;
            animation-fill-mode: both;
        }
    }
    @keyframes rotated {
        from {
            //Y轴:x+100px
            transform: translateY(100px);
        }
        to {
            //Y轴:x-100px
            transform: translateY(-100px);
        }
    }
}

2.css

* {
  margin: 0;
  padding: 0;
}
* #wrap {
  position: absolute;
  width: 600px;
  height: 600px;
  background: url(../img/my-logo-2.png) repeat;
  background-size: 50px;
  border: 1px solid #000000;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  margin-left: -300px;
  margin-top: -300px;
}
* #wrap:hover #wrap-inner {
  animation-play-state: paused;
}
* #wrap #wrap-inner {
  position: absolute;
  width: 300px;
  height: 300px;
  background: tomato;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 2px 2px 5px tomato;
  font: 30px/300px "微软雅黑";
  text-align: center;
  color: white;
  top: 50%;
  left: 50%;
  margin-left: -150px;
  margin-top: -150px;
  animation-name: rotated;
  animation-duration: 1.5s;
  animation-timing-function: cubic-bezier(0.12, 1.36, 0.65, -0.28);
  animation-direction: alternate;
  animation-iteration-count: 6;
  animation-delay: 1s;
  /*元素在动画外的状态: from之前to之后
              1. backwards与from一致=动画开始的动作,结束回归原位
              2. forwards与to一致=动画结束的动作,结束不回归原位
              3. both=动画开始/结束的动作,开始/结束不回归原位
            */
  animation-fill-mode: both;
}
@keyframes rotated {
  from {
    transform: translateY(100px);
  }
  to {
    transform: translateY(-100px);
  }
}

3.html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>动画模式@keyframes{}</title>
	</head>
	<body>
		<div id="wrap">
			<div id="wrap-inner">cevent</div>
		</div>
	</body>
	<link rel="stylesheet" href="css/less034.css" />
</html>

4.效果图

cevent

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值