• vantajs使用


    vantajs可用于背景图展示动态效果,vue中使用方式如下:

    安装依赖,注意版本,three的最新版本可能会报错

    npm i vanta@0.5.24 three@0.121.0
    1. <template>
    2. <div id="app">
    3. <div ref="vantaRef" style="height: 30vh;"></div>
    4. <div ref="BIRDS" style="display:inline-block;width:30vw;height: 30vh;"></div>
    5. <div ref="Cells" style="display:inline-block;width:30vw;height: 30vh;"></div>
    6. <div ref="Clouds" style="display:inline-block;width:30vw;height: 30vh;"></div>
    7. <div ref="Clouds2" style="display:inline-block;width:30vw;height: 30vh;"></div>
    8. <div ref="Dots" style="display:inline-block;width:30vw;height: 30vh;"></div>
    9. <div ref="Fog" style="display:inline-block;width:30vw;height: 30vh;"></div>
    10. <div ref="Globe" style="display:inline-block;width:30vw;height: 30vh;"></div>
    11. <div ref="Halo" style="display:inline-block;width:30vw;height: 30vh;"></div>
    12. <div ref="Net" style="display:inline-block;width:30vw;height: 30vh;"></div>
    13. <div ref="Rings" style="display:inline-block;width:30vw;height: 30vh;"></div>
    14. <div ref="Ripple" style="display:inline-block;width:30vw;height: 30vh;"></div>
    15. <div ref="Topology" style="display:inline-block;width:30vw;height: 30vh;"></div>
    16. <div ref="Trunk" style="display:inline-block;width:30vw;height: 30vh;"></div>
    17. <div ref="WAVES" style="display:inline-block;width:30vw;height: 30vh;"></div>
    18. </div>
    19. </template>
    20. <script>
    21. import * as THREE from 'three'
    22. import BIRDS from "vanta/dist/vanta.birds.min";
    23. import Cells from "vanta/dist/vanta.cells.min";
    24. import Clouds from "vanta/dist/vanta.clouds.min";
    25. import Clouds2 from "vanta/dist/vanta.clouds2.min"; //有问题
    26. import Dots from "vanta/dist/vanta.dots.min"; //有bug
    27. import Fog from "vanta/dist/vanta.fog.min";
    28. import Globe from "vanta/dist/vanta.globe.min";
    29. import Halo from "vanta/dist/vanta.halo.min";
    30. import Net from "vanta/dist/vanta.net.min";
    31. import Rings from "vanta/dist/vanta.rings.min";
    32. import Ripple from "vanta/dist/vanta.ripple.min";//不好看
    33. import Topology from "vanta/dist/vanta.topology.min"; //有bug
    34. import Trunk from "vanta/dist/vanta.trunk.min"; //有bug
    35. import WAVES from "vanta/dist/vanta.waves.min";
    36. export default {
    37. data() {
    38. return {
    39. vantaEffect: null,
    40. }
    41. },
    42. mounted() {
    43. this.vantaEffect = Clouds({
    44. el: this.$refs.vantaRef,
    45. THREE: THREE,
    46. mouseControls: true,
    47. touchControls: true,
    48. gyroControls: false,
    49. minHeight: 200.00,
    50. minWidth: 200.00,
    51. scale: 1.00,
    52. scaleMobile: 1.00,
    53. })
    54. BIRDS({
    55. el: this.$refs.BIRDS,
    56. THREE: THREE,
    57. })
    58. Cells({
    59. el: this.$refs.Cells,
    60. THREE: THREE,
    61. })
    62. Clouds({
    63. el: this.$refs.Clouds,
    64. THREE: THREE,
    65. })
    66. Clouds2({
    67. el: this.$refs.Clouds2,
    68. THREE: THREE,
    69. })
    70. Dots({
    71. el: this.$refs.Dots,
    72. THREE: THREE,
    73. })
    74. Fog({
    75. el: this.$refs.Fog,
    76. THREE: THREE,
    77. })
    78. Globe({
    79. el: this.$refs.Globe,
    80. THREE: THREE,
    81. color: 0xff4484,
    82. backgroundColor: 0x24153d
    83. })
    84. Halo({
    85. el: this.$refs.Halo,
    86. THREE: THREE,
    87. baseColor: 0x1b5d,
    88. backgroundColor: 0x151d49
    89. })
    90. Net({
    91. el: this.$refs.Net,
    92. THREE: THREE,
    93. color: 0x40f9c9,
    94. backgroundColor: 0x23163a
    95. })
    96. Rings({
    97. el: this.$refs.Rings,
    98. THREE: THREE,
    99. backgroundColor: 0x1f2226,
    100. color: 0x86ff00
    101. })
    102. Ripple({
    103. el: this.$refs.Ripple,
    104. THREE: THREE,
    105. })
    106. Topology({
    107. el: this.$refs.Topology,
    108. THREE: THREE,
    109. })
    110. Trunk({
    111. el: this.$refs.Trunk,
    112. THREE: THREE,
    113. })
    114. WAVES({
    115. el: this.$refs.WAVES,
    116. THREE: THREE,
    117. })
    118. },
    119. beforeDestroy() {
    120. if (this.vantaEffect) {
    121. this.vantaEffect.destroy();
    122. }
    123. },
    124. }
    125. </script>

    参考官方实例:https://www.vantajs.com/?effect=clouds

    参考git代码:https://github.com/tengbao/vanta

  • 相关阅读:
    网络安全(黑客技术)—2024自学
    弹性力学之边界条件
    【python学习第12节 pandas】
    如何用R语言在机器学习中建立集成模型?
    pyserial,win11,串口总是被占用
    docker 常用命令整理
    【工程部署】在RK3588上部署OCR(文字检测识别)(DBNet+CRNN)
    PostgreSQL执行计划介绍
    ElasticSearch这些坑记得避开
    基于Windows 的 VS Code C/C++ 编译环境搭建
  • 原文地址:https://blog.csdn.net/bamboozjy/article/details/133708064