经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS3 » 查看文章
用CSS3和table标签实现一个圆形轨迹的动画的示例代码_css3_CSS
来源:jb51  时间:2019/1/18 9:12:17  对本文有异议

html:其实就是根据table标签把几个实心圆div进行等边六角形的排布,并放入一个div容器中,然后利用CSS3的循环旋转的动画效果对最外层的div容器进行自转实现,当然不要忘了把div容器的外边框设置圆形弧度的。

  1. <div class="animation_div">
  2. <table class="table_class">
  3. <tr>
  4. <td></td>
  5. <td>
  6. <div class="BMI" ng-click="compriseClicked('BMI')" ng-class="{isSelected:clickUrlKey=='BMI'}">
  7. <strong>BMI</strong>
  8. </div>
  9. </td>
  10. <td></td>
  11. <td>
  12. <div class="color_blind" ng-click="compriseClicked('color_blind')" ng-class="{isSelected:clickUrlKey=='color_blind'}">
  13. <strong>色盲色弱</strong>
  14. </div>
  15. </td>
  16. <td></td>
  17. </tr>
  18. <tr>
  19. <td>
  20. <div class="space_div"></div>
  21. </td>
  22. </tr>
  23. <tr>
  24. <td>
  25. <div class="HR" ng-click="compriseClicked('HR')" ng-class="{isSelected:clickUrlKey=='HR'}">
  26. <strong>心率</strong>
  27. </div>
  28. </td>
  29. <td></td>
  30. <td>
  31. <a href="#/app/custom_made/counselor/{{clickUrlKey}}" style="text-decoration: none;
  32. color: black;">
  33. <div class="start_test">
  34. <strong>开始测试</strong>
  35. </div>
  36. </a>
  37. </td>
  38. <td></td>
  39. <td>
  40. <div class="fat_content" ng-click="compriseClicked('fat_content')" ng-class="{isSelected:clickUrlKey=='fat_content'}">
  41. <strong>脂肪含量</strong>
  42. </div>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>
  47. <div class="space_div"></div>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td></td>
  52. <td>
  53. <div class="WHR" ng-click="compriseClicked('WHR')" ng-class="{isSelected:clickUrlKey=='WHR'}">
  54. <strong>腰臀比</strong>
  55. </div>
  56. </td>
  57. <td></td>
  58. <td>
  59. <div class="safe_period" ng-click="compriseClicked('safe_period')" ng-class="{isSelected:clickUrlKey=='safe_period'}">
  60. <strong>安全期</strong>
  61. </div>
  62. </td>
  63. <td></td>
  64. </tr>
  65. </table>
  66. </div>
  67. <h3>clickUrlKey:{{clickUrlKey}}</h3>

css:因为在圆形的轨迹中有6个实心圆,分别设置了不同的类以方便自定义,所以当中实心圆的样式设置有重复的地方,还可以进行优化,在这就先不处理了

  1. <style>
  2. /*定义动画*/
  3. @-webkit-keyframes round_animation {
  4. 0%{
  5. -webkit-transform:rotate(0deg);
  6. width:260px;
  7. height:260px;
  8. }
  9. 100%{
  10. -webkit-transform:rotate(360deg);
  11. width:260px;
  12. height:260px;
  13. left:0px;
  14. top:0px;
  15. }
  16. }
  17. /*定义外框的样式*/
  18. /*调用动画并设置动画的参数*/
  19. .animation_div {
  20. -webkit-transform-origin:center center; /*定义旋转中心点*/
  21. -webkit-animation:round_animation 15s infinite alternate; /*infinite alternate表示循环播放动画*/
  22. margin: 60px auto;
  23. width:260px;
  24. height:260px;
  25. border: 1px solid black;
  26. border-radius: 130px;
  27. left:0px;
  28. top:0px;
  29. }
  30. .animation_div strong {
  31. font-size: 12px;
  32. }
  33. .BMI {
  34. width: 50px;
  35. height: 50px;
  36. background-color: orange;
  37. border-radius: 100px;
  38. text-align: center;
  39. /*文字垂直居中*/
  40. vertical-align: middle;
  41. line-height: 50px;
  42. }
  43. .color_blind {
  44. width: 50px;
  45. height: 50px;
  46. background-color: green;
  47. border-radius: 100px;
  48. text-align: center;
  49. /*文字垂直居中*/
  50. vertical-align: middle;
  51. line-height: 50px;
  52. }
  53. .HR{
  54. margin-left: -15px;
  55. width: 50px;
  56. height: 50px;
  57. background-color: blue;
  58. border-radius: 100px;
  59. text-align: center;
  60. /*文字垂直居中*/
  61. vertical-align: middle;
  62. line-height: 50px;
  63. }
  64. .start_test {
  65. width: 60px;
  66. height: 60px;
  67. background-color: red;
  68. border-radius: 100px;
  69. text-align: center;
  70. /*文字垂直居中*/
  71. vertical-align: middle;
  72. line-height: 50px;
  73. }
  74. .fat_content {
  75. margin-left: 15px;
  76. width: 50px;
  77. height: 50px;
  78. background-color: gray;
  79. border-radius: 100px;
  80. text-align: center;
  81. /*文字垂直居中*/
  82. vertical-align: middle;
  83. line-height: 50px;
  84. }
  85. .WHR {
  86. width: 50px;
  87. height: 50px;
  88. background-color: purple;
  89. border-radius: 100px;
  90. text-align: center;
  91. /*文字垂直居中*/
  92. vertical-align: middle;
  93. line-height: 50px;
  94. }
  95. .safe_period {
  96. width: 50px;
  97. height: 50px;
  98. background-color: yellow;
  99. border-radius: 100px;
  100. text-align: center;
  101. /*文字垂直居中*/
  102. vertical-align: middle;
  103. line-height: 50px;
  104. }
  105. .space_div {
  106. width: 50px;
  107. height: 50px;
  108. background-color: clear;
  109. border-radius: 100px;
  110. }
  111. .rightmenu_btn {
  112. height: 60px;
  113. float: none;
  114. }
  115. .rightmenu_btn button {
  116. margin-top: 50px;
  117. width: 20px;
  118. height: 60px;
  119. border: 1px solid rgb(221, 221, 221);
  120. border-right: 0px;
  121. float: right;
  122. }
  123. .isSelected {
  124. border: 1px solid red;
  125. }
  126. </style>

JS:这里的代码可以不实现,因为这跟动画的效果无关,是一个点击的响应事件

  1. angular.module('starter.controllers', [])
  2. .controller('healthCtrl', function($scope, $location) {
  3. $scope.clickUrlKey = "BMI";
  4. $scope.compriseClicked = function(clickUrlKey) {
  5. $scope.clickUrlKey = clickUrlKey;
  6. };
  7. })

效果图如下:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持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号