欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

css3的animation动画属性实现闹钟左右摇摆

程序员文章站 2022-07-13 17:08:09
...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>闹钟震动</title>
<style>
#div1
{
	position: relative;
	height: 200px;
	width: 200px;
	margin: 100px;
	border: 1px solid black;
}

#div2
{
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 50px;
  width: 100px;
  height: 100px;
	border: 1px solid black;
	background-color: red;
  animation: myfirst 5s;
}
@keyframes myfirst
{
  0% {
    transform: rotate(-15deg);
  }
  2% {
    transform: rotate(15deg);
  }
  4% {
    transform: rotate(-18deg);
  }
  6% {
    transform: rotate(18deg);
  }
  8% {
    transform: rotate(-22deg);
  }
  10% {
    transform: rotate(22deg);
  }
  12% {
    transform: rotate(-18deg);
  }
  14% {
    transform: rotate(18deg);
  }
  16% {
    transform: rotate(-12deg);
  }
  18% {
    transform: rotate(12deg);
  }
  20% {
    transform: rotate(0deg);
  }
}
 
</style>
</head>

<body>

<div id="div1">
  <div id="div2">闹钟</div>
</div>

</body>
</html>
相关标签: CSS属性