CSS3中怎么实现过渡transition效果

2023-05-23,

这篇文章将为大家详细讲解有关CSS3中怎么实现过渡transition效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

具体内容如下

效果图:

实现代码:

transition.html

  1. <!DOCTYPE html>     

  2. <html lang="en">     

  3. <head>     

  4.     <meta charset="UTF-8">     

  5.     <title>Transition</title>     

  6.     <style>     

  7.         #block {     

  8.             width: 400px;     

  9.             height: 300px;     

  10.             background-color: #69C;     

  11.             margin: 0 auto;     

  12.      

  13.             transition: background-color 1s, width 0.5s ease-out;     

  14.             -webkit-transition: background-color 1s, width 0.5s ease-out;     

  15.         }     

  16.         #block:hover {     

  17.             background-color: red;     

  18.             width: 600px;     

  19.         }     

  20.     </style>     

  21. </head>     

  22. <body>     

  23.     <div id="block">     

  24.      

  25.     </div>     

  26. </body>     

  27. </html>    

transitionDemo.html

XML/HTML Code复制内容到剪贴板

  1. <!DOCTYPE html>     

  2. <html lang="en">     

  3. <head>     

  4.     <meta charset="UTF-8">     

  5.     <title>TransitionDemo</title>     

  6.     <style>     

  7.         #wrapper {     

  8.             width: 1024px;     

  9.             margin: 0 auto;     

  10.         }     

  11.         .progress-bar-bg {     

  12.             width: 960px;     

  13.             /*background-color: aliceblue;*/     

  14.             background-color: lightyellow;     

  15.         }     

  16.         .progress-bar {     

  17.             height: 40px;     

  18.             width: 40px;     

  19.             background-color: #69C;     

  20.      

  21.             border: 1px solid lightyellow;     

  22.             border-radius: 5px;     

  23.         }     

  24.         .progress-bar:hover {     

  25.             width: 960px;     

  26.         }     

  27.      

  28.         #bar1 {     

  29.             -webkit-transition: width 5s linear;     

  30.             /*-webkit-transition: width 5s steps(6, end);*/     

  31.             /*-webkit-transition: width 5s step-start;*/     

  32.         }     

  33.         #bar2 {     

  34.             -webkit-transition: width 5s ease;     

  35.         }     

  36.         #bar3 {     

  37.             -webkit-transition: width 5s ease-in;     

  38.         }     

  39.         #bar4 {     

  40.             -webkit-transition: width 5s ease-out;     

  41.         }     

  42.         #bar5 {     

  43.             -webkit-transition: width 5s ease-in-out;     

  44.         }     

  45.     </style>     

  46. </head>     

  47. <body>     

  48. <div id="wrapper">     

  49.     <p>linear</p>     

  50.     <div class="progress-bar-bg">     

  51.         <div class="progress-bar" id="bar1"></div>     

  52.     </div>     

  53.      

  54.     <p>ease</p>     

  55.     <div class="progress-bar" id="bar2"></div>     

  56.      

  57.     <p>ease-in</p>     

  58.     <div class="progress-bar" id="bar3"></div>     

  59.      

  60.     <p>ease-out</p>     

  61.     <div class="progress-bar" id="bar4"></div>     

  62.      

  63.     <p>ease-in-out</p>     

  64.     <div class="progress-bar" id="bar5"></div>     

  65. </div>     

  66. </body>     

  67. </html>   

关于CSS3中怎么实现过渡transition效果就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

《CSS3中怎么实现过渡transition效果.doc》

下载本文的Word格式文档,以方便收藏与打印。