- <title>animation拆分写法</title>
- <style>
- .box {
- width: 200px;
- height: 100px;
- background-color: pink;
-
- /* 动画名称 */
- animation-name: change;
- /* 动画时长 */
- animation-duration: 1s;
- /* 播放次数 */
- animation-iteration-count: infinite;
- /* animation-play-state: paused; */
- }
- .box:hover {
- /* 暂停动画 */
- animation-play-state: paused;
- }
- /* 宽度从 200 变化到 800 */
- @keyframes change {
- 0% {
- width: 200px;
- }
- 100% {
- width: 800px;
- }
- }
- </style>
- </head>
- <body>
- <div class="box"></div>
- </body>
复制代码
- <title>走马灯</title>
- <style>
- * {
- padding: 0;
- margin: 0;
- }
- li {
- list-style: none;
- }
- img {
- display: block;
- width: 200px;
- }
-
- .box {
- width: 600px;
- height: 112px;
- border: 5px solid #000;
- margin: 100px auto;
- overflow: hidden;
- }
- .box ul {
- display: flex;
- animation: move 6s infinite linear;
- }
- /* 定义位移动画;ul使用动画;鼠标悬停暂停动画 */
- @keyframes move {
- 0% {
- transform: translate(0);
- }
- 100% {
- transform: translate(-1400px);
- }
- }
- .box:hover ul {
- animation-play-state: paused;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <ul>
- <li><img src="./images/1.jpg" alt="" /></li>
- <li><img src="./images/2.jpg" alt="" /></li>
- <li><img src="./images/3.jpg" alt="" /></li>
- <li><img src="./images/4.jpg" alt="" /></li>
- <li><img src="./images/5.jpg" alt="" /></li>
- <li><img src="./images/6.jpg" alt="" /></li>
- <li><img src="./images/7.jpg" alt="" /></li>
- <!-- 替身:填补显示区域的露白 -->
- <li><img src="./images/1.jpg" alt="" /></li>
- <li><img src="./images/2.jpg" alt="" /></li>
- <li><img src="./images/3.jpg" alt="" /></li>
- </ul>
- </div>
- </body>
复制代码
- <title>精灵动画</title>
- <style>
- div {
- width: 140px;
- height: 140px;
- border: 1px solid #000;
- background-image: url(./images/bg.png);
- animation: run 1s steps(12) infinite;
- }
- @keyframes run {
- from {
- background-position: 0 0;
- }
- to {
- background-position: -1680px 0;
- }
- }
- </style>
- </head>
- <body>
- <div></div>
- </body>
复制代码
- <title>多组动画</title>
- <style>
- div {
- width: 140px;
- height: 140px;
- /* border: 1px solid #000; */
- background-image: url(./images/bg.png);
- animation:
- run 1s steps(12) infinite,
- move 3s forwards
- ;
- }
- /* 当动画的开始状态样式 跟 盒子默认样式相同,可以省略动画开始状态的代码 */
- @keyframes run {
- /* from {
- background-position: 0 0;
- } */
- to {
- background-position: -1680px 0;
- }
- }
- @keyframes move {
- /* 0% {
- transform: translate(0);
- } */
- 100% {
- transform: translate(800px);
- }
- }
- </style>
- </head>
- <body>
- <div></div>
- </body>
复制代码
<title>全民出游季</title>
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<!-- 云 -->
<div class="cloud">
<img src="./images/yun1.png" alt="">
<img src="./images/yun2.png" alt="">
<img src="./images/yun3.png" alt="">
</div>
<!-- 文字 -->
<div class="text">
<img src="./images/font1.png" alt="">
</div>
</body>- * {
- margin: 0;
- padding: 0;
- }
- /* 大背景 */
- /* 默认状态HTML和body的高度是0,所以导致cover缩放背景图不成功 */
- html {
- height: 100%;
- }
- body {
- height: 100%;
- background: url(../images/f1_1.jpg) no-repeat center 0 / cover;
- /* background-size: cover; */
- }
- /* 云 */
- .cloud img {
- position: absolute;
- left: 50%;
- }
- .cloud img:nth-child(1) {
- margin-left: -250px;
- top: 20px;
- animation: cloud 1s infinite alternate linear;
- }
- .cloud img:nth-child(2) {
- margin-left: 400px;
- top: 100px;
- animation: cloud 1s infinite alternate linear 0.4s;
- }
- .cloud img:nth-child(3) {
- margin-left: -550px;
- top: 200px;
- animation: cloud 1s infinite alternate linear 0.6s;
- }
- @keyframes cloud {
- 100% {
- transform: translate(20px);
- }
- }
- /* 文字 */
- .text img {
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- animation: text 1s;
- }
- /* 默认 → 小 → 大 → 小 → 默认 */
- @keyframes text {
- 0% {
- transform: translate(-50%, -50%) scale(1);
- }
- 20% {
- transform: translate(-50%, -50%) scale(0.1);
- }
- 40% {
- transform: translate(-50%, -50%) scale(1.4);
- }
- 70% {
- transform: translate(-50%, -50%) scale(0.8);
- }
- 100% {
- transform: translate(-50%, -50%) scale(1);
- }
- }
复制代码
|