经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS3 » 查看文章
CSS3 实现倒计时效果_css3_CSS
来源:jb51  时间:2020/11/23 11:51:02  对本文有异议

实现效果

html

  1. %div.wrapper
  2. %div.time-part-wrapper
  3. %div.time-part.minutes.tens
  4. %div.digit-wrapper
  5. %span.digit 0
  6. - (-5..0).each do |i|
  7. %span.digit= -i
  8. %div.time-part.minutes.ones
  9. %div.digit-wrapper
  10. %span.digit 0
  11. - (-9..0).each do |i|
  12. %span.digit= -i
  13.  
  14. %div.time-part-wrapper
  15. %div.time-part.seconds.tens
  16. %div.digit-wrapper
  17. %span.digit 0
  18. - (-5..0).each do |i|
  19. %span.digit= -i
  20. %div.time-part.seconds.ones
  21. %div.digit-wrapper
  22. %span.digit 0
  23. - (-9..0).each do |i|
  24. %span.digit= -i
  25. %div.time-part-wrapper
  26. %div.time-part.hundredths.tens
  27. %div.digit-wrapper
  28. %span.digit 0
  29. - (-9..0).each do |i|
  30. %span.digit= -i
  31. %div.time-part.hundredths.ones
  32. %div.digit-wrapper
  33. %span.digit 0
  34. - (-9..0).each do |i|
  35. %span.digit= -i

css

  1. @import "compass/css3";
  2.  
  3. /* Play with speed and easing of the animation */
  4. $one-second: 1s;
  5. $easing: cubic-bezier(1,0,1,0);
  6. /* =========================================== */
  7.  
  8. @mixin animate($count) {
  9. $step: (100 / $count);
  10. $progress: 0%;
  11. $translate: -$digit-height;
  12. @while $progress < 100 {
  13. #{$progress} { transform: translateY($translate); }
  14. $progress: $progress + $step;
  15. $translate: $translate - $digit-height;
  16. }
  17. }
  18.  
  19. $digit-height: 180px;
  20.  
  21. .digit {
  22. display: inline-block;
  23. font-size: 200px;
  24. color: rgba(0,0,0,0.25);
  25. height: $digit-height;
  26. line-height: 1;
  27. }
  28.  
  29. .time-part-wrapper {
  30. display: inline-block;
  31. margin-right: 50px;
  32. position: relative;
  33.  
  34. &:not(:last-child):after {
  35. content: ":";
  36. display: block;
  37. width: 30px;
  38. height: 230px;
  39. position: absolute;
  40. top: 0px;
  41. right: -30px;
  42. color: rgba(0,0,0,0.25);
  43. font-size: 200px;
  44. line-height: 0.9;
  45. }
  46. }
  47.  
  48. .time-part {
  49. width: 140px;
  50. text-align: center;
  51. height: $digit-height;
  52. overflow: hidden;
  53. display: inline-block;
  54. margin-left: -5px;
  55. box-sizing: border-box;
  56. .digit-wrapper {
  57. animation-timing-function: $easing;
  58. }
  59. &.minutes {
  60. &.tens .digit-wrapper {
  61. animation-name: minutes-tens;
  62. animation-duration: $one-second * 10 * 6 * 10 * 6;
  63. animation-iteration-count: 1;
  64. }
  65. &.ones .digit-wrapper {
  66. animation-name: minutes-ones;
  67. animation-duration: $one-second * 10 * 6 * 10;
  68. animation-iteration-count: 6;
  69. }
  70. }
  71. &.seconds {
  72. &.tens .digit-wrapper {
  73. animation-name: seconds-tens;
  74. animation-duration: $one-second * 10 * 6;
  75. animation-iteration-count: 60;
  76. }
  77. &.ones .digit-wrapper {
  78. animation-name: seconds-ones;
  79. animation-duration: $one-second * 10;
  80. animation-iteration-count: 360;
  81. }
  82. }
  83. &.hundredths {
  84. &.tens .digit-wrapper {
  85. animation-name: hundredths-tens;
  86. animation-duration: $one-second;
  87. animation-iteration-count: 3600;
  88. }
  89. &.ones .digit-wrapper {
  90. animation-name: hundredths-ones;
  91. animation-duration: $one-second / 10;
  92. animation-iteration-count: 36000;
  93. }
  94. }
  95. }
  96.  
  97. @keyframes minutes-tens {
  98. @include animate(6);
  99. }
  100. @keyframes minutes-ones {
  101. @include animate(10);
  102. }
  103.  
  104. @keyframes seconds-tens {
  105. @include animate(6);
  106. }
  107. @keyframes seconds-ones {
  108. @include animate(10);
  109. }
  110.  
  111. @keyframes hundredths-tens {
  112. @include animate(10);
  113. }
  114. @keyframes hundredths-ones {
  115. @include animate(10);
  116. }
  117.  
  118. body {
  119. background: #F1614B;
  120. margin: 0;
  121. font-family: "Aldrich";
  122. }
  123.  
  124. .wrapper {
  125. margin: 100px auto;
  126. width: 1000px;
  127. position: relative;
  128. &:before, &:after {
  129. content: "";
  130. display: block;
  131. position: absolute;
  132. width: 100%;
  133. left: 0;
  134. height: 20px;
  135. z-index: 10;
  136. }
  137. &:before {
  138. top: 0px;
  139. @include background-image(linear-gradient(top, rgba(241,97,75,1) 0%,rgba(241,97,75,0) 100%));
  140. }
  141. &:after {
  142. bottom: 0px;
  143. @include background-image(linear-gradient(top, rgba(241,97,75,0) 0%,rgba(241,97,75,1) 100%));
  144. }
  145. }

以上就是CSS3 实现倒计时效果的详细内容,更多关于CSS3 倒计时的资料请关注w3xue其它相关文章!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号