CSS 动画:animation和transition
2017-05-04 17:28
537 查看
animation
animation使用时必须配合@keyframes<!DOCTYPE html> <html> <head> <style> div { width:100px; height:100px; background:red; position:relative; animation:mymove 5s infinite; -webkit-animation:mymove 5s infinite; /*Safari and Chrome*/ } @keyframes mymove { from {left:0px;} to {left:200px;} } @-webkit-keyframes mymove /*Safari and Chrome*/ { from {left:0px;} to {left:200px;} } </style> </head> <body> <p><strong>注释:</strong>Internet Explorer 9 以及更早的版本不支持 animation 属性。</p> <div></div> </body> </html>
运行结果可见:http://www.w3school.com.cn/tiy/t.asp?f=css3_animation
transition
<!DOCTYPE html> <html> <head> <style> div { width:100px; height:100px; background:blue; transition:width 2s; -moz-transition:width 2s; /* Firefox 4 */ -webkit-transition:width 2s; /* Safari and Chrome */ -o-transition:width 2s; /* Opera */ } div:hover { width:300px; } </style> </head> <body> <div></div> <p>请把鼠标指针移动到蓝色的 div 元素上,就可以看到过渡效果。</p> <p><b>注释:</b>本例在 Internet Explorer 中无效。</p> </body> </html>
示例:http://www.w3school.com.cn/tiy/t.asp?f=css3_transition
除了使用hover,我们也可以这样写:
<!DOCTYPE html> <html> <head> <style> div { width:100px; height:100px; background:blue; transition:width 2s; -moz-transition:width 2s; /* Firefox 4 */ -webkit-transition:width 2s; /* Safari and Chrome */ -o-transition:width 2s; /* Opera */ } .widthnew{ width:300px; } </style> </head> <body> <div onclick="changewidth()"></div> </body> <script type="text/javascript"> function changewidth(){ console.log("console"); document.querySelector("div").className = 'widthnew'; } </script> </html>
相关文章推荐
- CSS的过渡效果及动画效果:transition&animation
- CSS动画 animation与transition
- transition和animation做动画(css动画二)
- CSS动画中的Animation和Transition全属性实例
- css动画——transition和animation
- Css Transition Animation 动画效果简介
- 前端动画大全:css的transition、css3的animation、Jquery的animate、js的setInterval
- css 动画 transform transition animation
- 13.(初级)CSS变形transform、过度transition、动画animation注意点及如何让动画更流畅方法
- css 动画 transition及animation
- CSS中动画:transition , transform , animation
- js判断css动画是否完成 animation,transition
- css过度动画案例解析(transition和animation)
- CSS3中的动画,animation、transition和transform属性的运用
- Css3 3d animation Step1---介绍如何实现css动画
- CSS3中和动画有关的属性transform、transition 和 animation
- 【CSS3】transition过渡和animation动画
- css3 炫酷的动画transform, transition, animation
- 【CSS3】transition过渡和animation动画
- css高度从0到auto的transition动画