transition属性的使用方法:transition:property duration timing-function;
其中property表示对哪个属性进行平滑过渡,duration表示多长时间完成属性值的平滑过渡,timing-function表示通过什么方法来进行平滑过渡。
多平滑过渡示例:
1 nbsp;html> 2 3 4 <meta> 5 <meta> 6 <meta> 7 <title>测试</title> 8 9 10 <div></div>11 <style>12 #test{13 width: 500px;14 height: 500px;15 background-color: yellow;16 /*<a style='color:#f60; text-decoration:underline;' href="https://www.php.cn/zt/15716.html" target="_blank">css动画*/17 transform: rotate(0);18 -webkit-transition: transform 0.5s linear, width 0.5s linear;19 -moz-transition: transform 0.5s linear, width 0.5s linear;20 -ms-transition: transform 0.5s linear, width 0.5s linear;21 -o-transition: transform 0.5s linear, width 0.5s linear;22 transition: transform 0.5s linear, width 0.5s linear;23 }24 #test:hover{25 width: 200px;26 transform: rotate(180deg);27 }28 </style>29 30
使用示例:
1 nbsp;html> 2 3 4 <meta> 5 <meta> 6 <meta> 7 <title>测试</title> 8 9 10 <div></div>11 <style>12 /*animation动画*/13 @-webkit-keyframes colorChange {14 0%{15 background-color: deepskyblue;16 } 50%{18 background-color: red;19 }20 100%{21 background-color: deepskyblue;22 }23 }24 #test{25 width:500px;26 height: 500px;27 background-color: deepskyblue;28 }29 #test:hover{30 animation-name: colorChange; animation-duration: 1s;32 animation-timing-function: linear;33 }34 </style>35 36
实现动画的方法:
方法 | 属性值的变化速度 |
linear | 在动画开始时与结束时以同样的速度进行变化 |
ease-in | 动画开始时速度很慢,然后速度沿曲线值进行加快 |
ease-out | 动画开始时速度很快,然后速度沿曲线值进行放慢 |
ease | 动画开始时速度很慢,然后速度沿曲线值进行加快,然后再沿曲线值进行放慢 |
ease-in-out | 动画开始时速度很慢,然后速度沿曲线值进行加快,然后再沿曲线值进行放慢 |
以上就是CSS3中transition功能怎么使用?的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号