• 如何使用HTML和CSS创建动画条形图?


    概述

    动画栏是使用 HTML 和 CSS 创建的图形动画栏。动画栏的布局是使用 HTML 创建的,栏的样式是使用 CSS 制作的。普通的条形图可以正常创建,但我们必须创建带有动画的条形图,因此我们将使用 CSS 过渡动画属性来使其具有动画效果。我们将构建一个与音乐动画条同步器相同的动画条。

    算法

    第 1 步 - 在文本编辑器中创建一个 HTML 文件并在其中添加 HTML 样板。

    第 2 步 − 现在创建一个包含动画线条的父 div 容器。

    <div class="animatedLines"></div>

     第 3 步 − 在父 div 内创建一个 div 子容器。创建至少七个“div”来制作一个好的动画栏,并将类名作为线条添加到其中。

    1. <div class="lines"></div>
    2. <div class="lines"></div>
    3. <div class="lines"></div>
    4. <div class="lines"></div>
    5. <div class="lines"></div>
    6. <div class="lines"></div>
    7. <div class="lines"></div>
    8. <div class="lines"></div>

     第 4 步 − 现在创建一个 style.css 文件并将该文件链接到 HTML 文档。

    <link rel="stylesheet" href="style.css">

     第 5 步− 在 style.css 文件中设置 HTML 元素的样式。

    1. .animatedLines {
    2. display: flex;
    3. justify-content: center;
    4. padding-top: 2rem;
    5. }
    6. .animatedLines .lines:nth-child(1) {
    7. animation-delay: .1s;
    8. background-color: rgb(141, 255, 88);
    9. }
    10. .animatedLines .lines:nth-child(2) {
    11. animation-delay: .2s;
    12. background-color: rgb(127, 253, 69);
    13. }
    14. .animatedLines .lines:nth-child(3) {
    15. animation-delay: .3s;
    16. background-color: rgb(18, 49, 6);
    17. }
    18. .animatedLines .lines:nth-child(4) {
    19. animation-delay: .4s;
    20. background-color: rgb(18, 49, 6);
    21. }
    22. .animatedLines .lines:nth-child(5) {
    23. animation-delay: .3s;
    24. background-color: rgb(18, 49, 6);
    25. }
    26. .animatedLines .lines:nth-child(6) {
    27. animation-delay: .2s;
    28. background-color: rgb(127, 253, 69);
    29. }
    30. .animatedLines .lines:nth-child(7) {
    31. animation-delay: .1s;
    32. background-color: rgb(102, 228, 43);
    33. }

     第 6 步 − 通过定位子“div”容器的类名来制作这些线条的动画。

    1. .animatedLines .lines {
    2. list-style: none;
    3. width: 5px;
    4. height: 10px;
    5. margin: 0 4px;
    6. animation: animatedBars .5s infinite alternate;
    7. }
    8. @keyframes animatedBars {
    9. 0% {
    10. transform: scaleY(1);
    11. }
    12. 25% {
    13. transform: scaleY(1);
    14. }
    15. 50% {
    16. transform: scaleY(1);
    17. }
    18. 100% {
    19. transform: scaleY(6);
    20. }
    21. }

     

    第 7 步− 动画条已成功创建。

    示例

    在此示例中,我们创建了一个动画栏。为此,我们创建了两个文件:index.html 和 style.css。索引文件包含页面的布局,style.css 文件包含页面的样式部分。

    1. <html>
    2. <head>
    3. <title>animated bars</title>
    4. <link rel="stylesheet" href="style.css">
    5. <style>
    6. .animatedLines {
    7. display: flex;
    8. justify-content: center;
    9. padding-top: 2rem;
    10. }
    11. .animatedLines .lines:nth-child(1) {
    12. animation-delay: .1s;
    13. background-color: rgb(141, 255, 88);
    14. }
    15. .animatedLines .lines:nth-child(2) {
    16. animation-delay: .2s;
    17. background-color: rgb(127, 253, 69);
    18. }
    19. .animatedLines .lines:nth-child(3) {
    20. animation-delay: .3s;
    21. background-color: rgb(18, 49, 6);
    22. }
    23. .animatedLines .lines:nth-child(4) {
    24. animation-delay: .4s;
    25. background-color: rgb(18, 49, 6);
    26. }
    27. .animatedLines .lines:nth-child(5) {
    28. animation-delay: .3s;
    29. background-color: rgb(18, 49, 6);
    30. }
    31. .animatedLines .lines:nth-child(6) {
    32. animation-delay: .2s;
    33. background-color: rgb(127, 253, 69);
    34. }
    35. .animatedLines .lines:nth-child(7) {
    36. animation-delay: .1s;
    37. background-color: rgb(102, 228, 43);
    38. }
    39. .animatedLines .lines {
    40. list-style: none;
    41. width: 5px;
    42. height: 10px;
    43. margin: 0 4px;
    44. animation: animatedBars .5s infinite alternate;
    45. }
    46. @keyframes animatedBars {
    47. 0% {
    48. transform: scaleY(1);
    49. }
    50. 25% {
    51. transform: scaleY(1);
    52. }
    53. 50% {
    54. transform: scaleY(1);
    55. }
    56. 100% {
    57. transform: scaleY(6);
    58. }
    59. }
    60. </style>
    61. </head>
    62. <body>
    63. <h1 style="text-align: center;text-decoration: underline;color: green;">tutorialspoint.com</h1>
    64. <div class="animatedLines">
    65. <div class="lines"></div>
    66. <div class="lines"></div>
    67. <div class="lines"></div>
    68. <div class="lines"></div>
    69. <div class="lines"></div>
    70. <div class="lines"></div>
    71. <div class="lines"></div>
    72. <div class="lines"></div>
    73. </div>
    74. </body>
    75. </html>

     

    下面给定的图像显示了上面示例的输出,它显示了一些您可以在浏览器上实时看到的动画线。当用户将此功能加载到浏览器中时,它会显示一条看起来更有吸引力的动画线条。

    结论

    动画栏的这一功能可以作为图形界面在语音合成器中使用。您还可以在许多应用程序中看到此组件,例如录音机和 dj 节拍同步器。上面例子中的主要部分是计时,我们设置了随着条形尺寸的增加而动画的计时。

  • 相关阅读:
    JSR303是啥?有啥用处?
    为什么做短视频你的一直不爆?
    IDEA为什么不能搜索到jar里的代码?
    vite+react+typescript 遇到的问题
    谷歌年薪100万+的测试猿怎么写 python 代码?
    springboot自习室管理系统 小程序毕业设计源码221535
    博客变现的15种方式大盘点
    [附源码]Python计算机毕业设计SSM久宠宠物店管理系统(程序+LW)
    C++变量与基本类型
    (6)SpringCloud-Spring Boot项目详细搭建步骤
  • 原文地址:https://blog.csdn.net/lwf3115841/article/details/132656969