赞
踩
目录
2 位移 :translate3d translateX translateY translateZ
3:旋转:rotate3d rotateX rotateY rotateZ
4:缩放:scale3d scaleX scaleY scaleZ
哪些属性要过渡(选 填)
注意:1、所有 数值类型 的属 性,都可以参与过渡, ⽐如width、height、 left、top、border,radius、opacity等2、从⼀个有效数值 向另⼀个有效数值进⾏ 过渡
指定过渡效果的持续时 间(必填)
过渡变化曲线(缓动效 果)(选填)
⽅法⼀:@keyframes 关键帧名称{from{初始状态属性}to{结束状态属性}}⽅法⼆:@keyframes 关键帧名称{0%{初始状态属性}50%(中间还可以再添加关键帧)100%{结束状态属性}
- @keyframes text {
- 2 /* from表示动画开始位置 也可以使⽤0%*/
- 3 from {
- 4 margin-left: 0;
- 5 }
- 6 /* to动画的结束位置 也可以使⽤100%*/
- 7 to {
- 8 margin-left: 500px;
- 9 }
第⼆步 调⽤关键帧
- //垂直⽔平居中的效果
- position: absolute;
- left: 50%;
- top: 50%;
- transform: translate(-50%, -50%);
- transform: translateX(-50%) translateY(-50%);
5.也不会影响其他盒⼦
x值:为正则向左变形,为负则向右变形y值:为正则向上变形,为负则向下变形以上是以左上⻆为参照向左向右,向上,向下变形
transform:skewX() ;transform:skewY();
transform-origin:(⽔平⽅向 垂直⽅向),默认值 transform-origin:(center center)值可以为⽅向值(left、center、top、right、bottom等),也可以是以px、%为单位的数值
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box{
- width: 200px;
- height: 200px;
- background-color: #bfa;
- margin: 50px auto;
- /* 设置过渡 */
- /* 设置过渡的元素属性 */
- /* transition-property: height background-color width; */
- /* transition-property: all; */
- /* 设置过渡的时间 */
- /* transition-duration: 1s; */
- /* 设置过渡的延迟 */
- /* transition-delay: 2s; */
- /* 设置过渡的变化曲线 */
- /* transition-timing-function:ease ; */
- transition:1s;
-
- }
- .box:hover{
- width: 300px;
- height: 300px;
- background-color: orange;
- opacity: 0;
- border-radius: 50%;
- }
- </style>
- </head>
- <body>
- <!-- 需求:鼠标移入,盒子高度变成300px -->
- <div class="box"></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Document</title>
- <style>
- * {
- padding: 0;
- margin: 0;
- text-decoration: none;
- list-style: none;
- }
- ul {
- width: 500px;
- height: 400px;
- border: 10px solid red;
- }
- li {
- width: 50px;
- height: 50px;
- border-radius: 50%;
- background-color: blueviolet;
- text-align: center;
- line-height: 50px;
- color: orange;
- margin: 5px 0px;
- /* 设置过渡 */
- transition-property: margin-left;
- transition-duration: 1s;
- }
- /* 设置不同的过渡曲线 */
- li:nth-child(1) {
- transition-timing-function: ease;
- }
- li:nth-child(1) {
- transition-timing-function: linear;
- }
- li:nth-child(2) {
- transition-timing-function: ease-in;
- }
- li:nth-child(3) {
- transition-timing-function: ease-out;
- }
- li:nth-child(4) {
- transition-timing-function: ease-in-out;
- }
- li:nth-child(5) {
- transition-timing-function: steps(5);
- }
-
- li:nth-child(2n) {
- background-color: aquamarine;
- }
- ul:hover > li {
- margin-left: 450px;
- }
- </style>
- </head>
- <body>
- <ul>
- <li>1</li>
- <li>2</li>
- <li>3</li>
- <li>4</li>
- <li>5</li>
- <li>6</li>
- </ul>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- div{
- width: 155px;
- height: 170px;
- background-image: url(./米兔照片.jpg);
- background-position: 0 0;
- transition: steps(4) 2s;
- }
- div:hover{
- background-position: -630px 0;
- }
-
- </style>
- </head>
- <body>
- <div></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta http-equiv="X-UA-Compatible" content="IE=edge" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>行走的雪人</title>
- <style>
- .box1 {
- width: 126px;
- height: 180px;
- background-image: url(./111.jpeg);
- animation: xueren 1s steps(4) infinite reverse ;
- }
- @keyframes xueren {
- from {
- background-position: 0 0;
- }
- to {
- background-position: -487px 0;
- }
- }
- </style>
- </head>
- <body>
- <div class="box1"></div>
- </body>
- </html>
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- .box {
- height: 500px;
- background-image: url(./images/bg.jpg);
- margin: 100px auto;
- position: relative;
- animation: shun 15s infinite linear both;
-
- }
-
-
- .text {
- position: absolute;
- /* border: 2px solid red; */
- left: 0;
- bottom: 0;
- }
-
- .shun {
- width: 200px;
- height: 180px;
- background-image: url(./images/1.png);
- animation: shun 1s steps(8) infinite reverse both;
- }
-
- .zhu {
- width: 200px;
- height: 180px;
- background-image: url(./images/2.png);
- animation: zhu 1s steps(8) infinite reverse both;
- }
-
- .tang {
- width: 150px;
- height: 200px;
- background-image: url(./images/3.png);
- animation: tang 1s steps(8) infinite reverse both;
- }
-
- .sa {
- width: 210px;
- height: 200px;
- background-image: url(./images/4.png);
- animation: sa 1s steps(8) infinite reverse both;
- }
-
- .box div {
- float: left;
-
- margin-right: 100px;
-
- }
- @keyframes box {
- from {
- background-position: 0%;
- }
-
- to {
- background-position: 100%;
- }
-
- }
-
- @keyframes shun {
- from {
- background-position: 0 0;
- }
-
- to {
- background-position: -1600px 0;
- }
-
- }
-
- @keyframes zhu {
- from {
- background-position: 0 0;
- }
-
- to {
- background-position: -1600px 0;
- }
-
- }
-
-
- @keyframes tang {
- from {
- background-position: 0 0;
- }
-
- to {
- background-position: -1360px 0;
- }
-
- }
-
- @keyframes sa {
- from {
- background-position: 0 0;
- }
-
- to {
- background-position: -1680px 0;
- }
-
- }
- </style>
- </head>
-
- <body>
-
-
-
- <div class="box">
-
- <div class="text">
-
- <div class="shun"></div>
- <div class="zhu"></div>
- <div class="tang"></div>
- <div class="sa"></div>
-
- </div>
-
- </div>
-
-
- </body>
-
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。