当前位置:   article > 正文

十分钟实现节日祝福动画,CSS+JavaScript实现元旦祝福动画,祝大家元旦快乐_网站 节日庆祝宣传图片 动画效果 js

网站 节日庆祝宣传图片 动画效果 js

视频 

视频地址:https://www.bilibili.com/video/BV1v54y1t7zn

十分钟实现元旦祝福动画,CSS+JavaScript实现节日祝福动画,祝大家元旦快乐

视频已同步到我的B站账号欢迎大家关注。
https://space.bilibili.com/563010186

参考代码

HTML:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>元旦快乐:公众号AlbertYang</title>
  6. <link rel="stylesheet" href="style.css">
  7. </head>
  8. <body>
  9. <p>
  10. <div class="box">
  11. <dic class="circle">
  12. <div class="text">
  13. <span style="--x:0"></span>
  14. <span style="--x:1"></span>
  15. <br />
  16. <span style="--x:2"></span>
  17. <span style="--x:3"></span>
  18. </div>
  19. </dic>
  20. </div>
  21. </p>
  22. <script>
  23. const bubbles = () => {
  24. let count = 300;
  25. let p = document.querySelector("p");
  26. for (let i = 0; i < count; i++) {
  27. let bubble = document.createElement('i');
  28. let x = Math.floor(Math.random() * window.innerWidth);
  29. y = Math.floor(Math.random() * window.innerHeight);
  30. let size = Math.random() * 60;
  31. bubble.style.left = x + 'px';
  32. bubble.style.top = y + 'px';
  33. bubble.style.width = size + 'px';
  34. bubble.style.height = size + 'px';
  35. bubble.style.animationDuration = 5 + size + 's';
  36. bubble.style.animationDelay = -size + 's';
  37. p.appendChild(bubble);
  38. }
  39. }
  40. bubbles()
  41. </script>
  42. </body>
  43. </html>

CSS:

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. overflow: hidden;
  8. }
  9. p {
  10. display: flex;
  11. justify-content: center;
  12. align-items: center;
  13. min-height: 100vh;
  14. background: #f1f1f1;
  15. }
  16. p .box {
  17. position: absolute;
  18. width: 450px;
  19. height: 450px;
  20. }
  21. p .box .circle {
  22. position: relative;
  23. width: 100%;
  24. height: 100%;
  25. background: linear-gradient(135deg, #fff, #e4e3e8);
  26. display: flex;
  27. justify-content: center;
  28. align-items: center;
  29. border-radius: 50%;
  30. }
  31. p .box .circle::before {
  32. content: "";
  33. position: absolute;
  34. left: 5px;
  35. top: 5px;
  36. right: 5px;
  37. bottom: 5px;
  38. background: linear-gradient(315deg, #fff, #e4e3e8);
  39. border-radius: 50%;
  40. z-index: 1;
  41. }
  42. p .text {
  43. position: absolute;
  44. font-size: 6em;
  45. color: #ff2a2a;
  46. z-index: 2;
  47. }
  48. p .text span {
  49. display: inline-block;
  50. animation: blink 3s 2s infinite;
  51. animation-delay: calc(var(--x) * 0.5s);
  52. }
  53. p i {
  54. position: absolute;
  55. background: #FF2A2A;
  56. border-radius: 50%;
  57. animation: animate linear infinite;
  58. }
  59. p i:nth-child(even) {
  60. background: transparent;
  61. border: 1px solid #FF2A2A;
  62. }
  63. @keyframes animate {
  64. 0% {
  65. transform: translateY(0);
  66. opacity: 0;
  67. filter: hue-rotate(0deg);
  68. }
  69. 10%,
  70. 90% {
  71. opacity: 1;
  72. }
  73. 100% {
  74. transform: translateY(-3000%);
  75. opacity: 0;
  76. filter: hue-rotate(36000deg);
  77. }
  78. }
  79. @keyframes blink {
  80. 0% {
  81. transform: scale(0);
  82. opacity: 0;
  83. filter: hue-rotate(0deg);
  84. }
  85. 30%,
  86. 50%,
  87. 80% {
  88. transform: scale(1.3);
  89. opacity: 1;
  90. }
  91. 100% {
  92. transform: scale(0);
  93. opacity: 0;
  94. filter: hue-rotate(3600deg);
  95. }
  96. }

今天的学习就到这里了,由于本人能力和知识有限,如果有写的不对的地方,还请各位大佬批评指正。如果想继续学习提高,欢迎关注我,每天进步一点点,就是领先的开始,加油。如果觉得本文对你有帮助的话,欢迎转发,评论,点赞!!!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/96395
推荐阅读
相关标签
  

闽ICP备14008679号