• 七、全屏粒子特效


    简介

    给页面添加粒子光影特效。⭐️ 欢迎访问个人的简历网站预览效果

    本章涉及修改与新增的文件:main.tsApp.vueutils
    在这里插入图片描述

    一、安装插件

    1. 安装 vue3-particles tsparticles插件 详细文档查看 tsParticles 官网
    npm i vue3-particles
    
    npm i tsparticles
    
    • 1
    • 2
    • 3
    1. 创建配置文件 options.ts
    // 在 utils 文件夹中 创建options.ts
    export const options = {
      "fullScreen": {
        "zIndex": 1
      },
      "particles": {
        "bounce": {
          "horizontal": {
            "random": {
              "enable": false,
              "minimumValue": 0.1
            },
            "value": 1
          },
          "vertical": {
            "random": {
              "enable": false,
              "minimumValue": 0.1
            },
            "value": 1
          }
        },
        "collisions": {
          "absorb": {
            "speed": 2
          },
          "bounce": {
            "horizontal": {
              "random": {
                "enable": false,
                "minimumValue": 0.1
              },
              "value": 1
            },
            "vertical": {
              "random": {
                "enable": false,
                "minimumValue": 0.1
              },
              "value": 1
            }
          },
          "enable": false,
          "maxSpeed": 50,
          "mode": "bounce",
          "overlap": {
            "enable": false,
            "retries": 0
          }
        },
        "color": {
          "value": "#F29927",
        },
        "groups": {},
        "move": {
          "angle": {
            "offset": 0,
            "value": 50
          },
          "attract": {
            "distance": 200,
            "enable": false,
            "rotate": {
              "x": 3000,
              "y": 3000
            }
          },
          "center": {
            "x": 50,
            "y": 50,
            "mode": "percent",
            "radius": 0
          },
          "decay": 0,
          "distance": {},
          "direction": "none",
          "drift": 0,
          "enable": true,
          "gravity": {
            "acceleration": 9.81,
            "enable": false,
            "inverse": false,
            "maxSpeed": 50
          },
          "path": {
            "clamp": true,
            "delay": {
              "random": {
                "enable": false,
                "minimumValue": 0
              },
              "value": 0
            },
            "enable": false,
            "options": {}
          },
          "outModes": {
            "default": "out",
            "bottom": "out",
            "left": "out",
            "right": "out",
            "top": "out"
          },
          "random": false,
          "size": false,
          "speed": 2,
          "spin": {
            "acceleration": 0,
            "enable": false
          },
          "straight": false,
          "trail": {
            "enable": false,
            "length": 10,
            "fill": {}
          },
          "vibrate": false,
          "warp": false
        },
        "number": {
          "density": {
            "enable": true,
            "width": 1920,
            "height": 1080
          },
          "limit": 0,
          "value": 50
        },
        "opacity": {
          "random": {
            "enable": true,
            "minimumValue": 0.5
          },
          "value": {
            "min": 0.3,
            "max": 1
          },
          "animation": {
            "count": 0,
            "enable": true,
            "speed": 0.5,
            "decay": 0,
            "delay": 0,
            "sync": false,
            "mode": "auto",
            "startValue": "random",
            "destroy": "none",
            "minimumValue": 0.3
          }
        },
        "shape": {
          "close": true,
          "fill": true,
          "options": {},
          "type": "circle"
        },
        "size": {
          "random": {
            "enable": true,
            "minimumValue": 1
          },
          "value": {
            "min": 1,
            "max": 3
          },
          "animation": {
            "count": 0,
            "enable": true,
            "speed": 3,
            "decay": 0,
            "delay": 0,
            "sync": false,
            "mode": "auto",
            "startValue": "random",
            "destroy": "none",
            "minimumValue": 1
          }
        },
        "stroke": {
          "width": 0
        },
        "zIndex": {
          "random": {
            "enable": false,
            "minimumValue": 0
          },
          "value": 0,
          "opacityRate": 1,
          "sizeRate": 1,
          "velocityRate": 1
        },
        "destroy": {
          "bounds": {},
          "mode": "none",
          "split": {
            "count": 1,
            "factor": {
              "random": {
                "enable": false,
                "minimumValue": 0
              },
              "value": 3
            },
            "rate": {
              "random": {
                "enable": false,
                "minimumValue": 0
              },
              "value": {
                "min": 4,
                "max": 9
              }
            },
            "sizeOffset": true,
            "particles": {}
          }
        },
        "roll": {
          "darken": {
            "enable": false,
            "value": 0
          },
          "enable": false,
          "enlighten": {
            "enable": false,
            "value": 0
          },
          "mode": "vertical",
          "speed": 25
        },
        "tilt": {
          "random": {
            "enable": false,
            "minimumValue": 0
          },
          "value": 0,
          "animation": {
            "enable": false,
            "speed": 0,
            "decay": 0,
            "sync": false
          },
          "direction": "clockwise",
          "enable": false
        },
        "twinkle": {
          "lines": {
            "enable": false,
            "frequency": 0.05,
            "opacity": 1
          },
          "particles": {
            "enable": false,
            "frequency": 0.05,
            "opacity": 1
          }
        },
        "wobble": {
          "distance": 5,
          "enable": false,
          "speed": {
            "angle": 50,
            "move": 10
          }
        },
        "life": {
          "count": 0,
          "delay": {
            "random": {
              "enable": false,
              "minimumValue": 0
            },
            "value": 0,
            "sync": false
          },
          "duration": {
            "random": {
              "enable": false,
              "minimumValue": 0.0001
            },
            "value": 0,
            "sync": false
          }
        },
        "rotate": {
          "random": {
            "enable": false,
            "minimumValue": 0
          },
          "value": 0,
          "animation": {
            "enable": false,
            "speed": 0,
            "decay": 0,
            "sync": false
          },
          "direction": "clockwise",
          "path": false
        },
        "orbit": {
          "animation": {
            "count": 0,
            "enable": false,
            "speed": 1,
            "decay": 0,
            "delay": 0,
            "sync": false
          },
          "enable": false,
          "opacity": 1,
          "rotation": {
            "random": {
              "enable": false,
              "minimumValue": 0
            },
            "value": 45
          },
          "width": 1
        },
        "links": {
          "blink": false,
          "color": {
            "value": "random"
          },
          "consent": false,
          "distance": 100,
          "enable": false,
          "frequency": 1,
          "opacity": 1,
          "shadow": {
            "blur": 5,
            "color": {
              "value": "#000"
            },
            "enable": false
          },
          "triangles": {
            "enable": false,
            "frequency": 1
          },
          "width": 1,
          "warp": false
        },
        "repulse": {
          "random": {
            "enable": false,
            "minimumValue": 0
          },
          "value": 0,
          "enabled": false,
          "distance": 1,
          "duration": 1,
          "factor": 1,
          "speed": 1
        }
      },
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357

    二、修改文件中代码

    1. main.ts 中引入插件
    import { createApp } from 'vue'
    import './style.css'
    import 'animate.css';
    import ElementPlus from 'element-plus'
    import 'element-plus/dist/index.css'
    import Particles from "vue3-particles";// 引入插件
    import App from './App.vue'
    const app = createApp(App)
    
    app.use(Particles)
    app.use(ElementPlus, { size: 'small', zIndex: 3000 })
    app.mount('#app')
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    1. App.vue 中使用插件
    <template>
      <div class="app-background" @wheel="handleWheel">
        <!-- 上一页信息 -->
        <div class="absolute" @click="prev" style="top: 50px;">
          <img src="/up.svg" class="logo" alt="Email" />
        </div>
    
        <el-carousel ref="carousel" height="100vh" trigger="click" direction="vertical" :autoplay="false"
          @change="changeCarousel">
          <el-carousel-item>
            <first :count="count" ref="firstPage" />
          </el-carousel-item>
          <el-carousel-item>
            <second :count="count" />
          </el-carousel-item>
          <el-carousel-item>
            <third :count="count" ref="thirdPage" />
          </el-carousel-item>
          <el-carousel-item>
            <fourth :count="count" ref="fourthPage" />
          </el-carousel-item>
          <el-carousel-item>
            <fifth :count="count" ref="fifthPage" @showProject="showProject" />
          </el-carousel-item>
        </el-carousel>
        <!-- 下一页信息 -->
        <div class="absolute" @click="next" style="bottom: 50px;">
          <img src="/down.svg" class="logo" alt="Email" />
        </div>
        <!-- 项目经验详情 -->
        <el-dialog v-model="showDialog" center>
          <div class="family">
            <div class="text18" style="text-align: center;font-weight: bold;">{{ projectInfo.projectName }}</div>
            <div class="margin-top" style="text-align: center;">
              {{ projectInfo.projectStartTime }} - {{ projectInfo.projectEndTime }}
            </div>
            <div class="flex margin-top">
              <div style="min-width: 100px;">项目描述:</div>
              <div>{{ projectInfo.projectDescription }}</div>
            </div>
            <div class="flex margin-top">
              <div style="min-width: 100px;">项目职责:</div>
              <div>{{ projectInfo.projectDuty }}</div>
            </div>
            <div class="flex margin-top">
              <div style="min-width: 100px;">技术栈:</div>
              <div>{{ projectInfo.projectStack }}</div>
            </div>
            <div class="flex margin-top" v-if="projectInfo.projectOnline">
              <div style="min-width: 100px;">线上地址:</div>
              <el-link :href="projectInfo.projectOnline" target="_blank">
                {{ projectInfo.projectOnline }}
              </el-link>
            </div>
          </div>
        </el-dialog>
    	// 使用粒子特效组件
        <vue-particles id="tsparticles" :particlesInit="particlesInit" :clickEffect="true" :options="options" />
      </div>
    </template>
    
    <script setup lang="ts">
    import first from './components/First.vue'
    import second from './components/Second.vue'
    import third from './components/Third.vue'
    import fourth from './components/Fourth.vue'
    import fifth from './components/Fifth.vue'
    import project from './utils/Project.ts'
    import { options } from "./utils/options";
    import { loadFull } from 'tsparticles'
    import { ref } from 'vue'
    const showDialog = ref(false)
    const projectInfo = ref(project['center'])
    const count = ref(0)
    const firstPage = ref()
    const thirdPage = ref()
    const fourthPage = ref()
    const fifthPage = ref()
    const carousel = ref()
    // 获取默认项目经验数据
    const showProject = (value: any) => {
      if (project[value]) {
        projectInfo.value = project[value]
        showDialog.value = true
      }
    }
    
    // 上一页
    const prev = () => {
      carousel.value.prev()
    }
    
    // 下一页
    const next = () => {
      carousel.value.next()
    }
    
    let timer: any = null
    const handleWheel = (e: any) => {
      if (showDialog.value) return
      let lock: Boolean = !timer;
      if (lock) {
        if (e.deltaY > 0) {
          next()
        } else if (e.deltaY < 0) {
          prev()
        }
        timer = setTimeout(() => {
          timer = null;
        }, 500);
      }
    }
    
    const handleKeyDown = (event: any) => {
      if (showDialog.value) return
      let lock: Boolean = !timer;
      if (lock) {
        if (event.key === 'ArrowUp') { prev() }
        else if (event.key === 'ArrowDown') { next() }
        timer = setTimeout(() => {
          timer = null;
        }, 500);
      }
    }
    // 监听键盘触发事件
    document.addEventListener('keydown', handleKeyDown);
    
    // 监听切换事件,重置和触发动态效果
    const changeCarousel = (value: any) => {
      count.value = value
      if (value === 0) {
        firstPage.value.resetArr()
      } else if (value === 2) {
        thirdPage.value.resetArr()
      } else if (value === 3) {
        fourthPage.value.resetArr()
      } else if (value === 4) {
        fifthPage.value.resetArr()
      }
    }
    
    const particlesInit = async (engine: any) => {
      await loadFull(engine)
    }
    </script>
    
    <style scoped>
    .app-background {
      position: relative;
      width: 100%;
      height: 100vh;
      background-image: url('./assets/bgBig.png');
      background-repeat: no-repeat;
      background-position: center 0;
      background-size: cover;
    }
    
    .el-carousel__item {
      min-height: 100vh;
      background-color: rgba(10, 10, 10, 0.3);
    }
    
    ::v-deep(.el-dialog) {
      background-color: rgb(250, 235, 215);
      animation: jackInTheBox;
      animation-duration: 1.5s;
    }
    
    .absolute {
      position: absolute;
      z-index: 10;
      left: calc(50% - 14px);
      opacity: .25;
      transition: all .4s linear 0s;
    }
    
    .absolute:hover {
      transform: scale(1.18);
      opacity: .85;
    }
    
    .logo {
      width: 28px;
      height: 28px;
    }
    </style> 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186

    效果如下:

    在这里插入图片描述

    => To Be Continued

    点赞 评论 收藏 ~~ 留言讨论,如有错误,也希望大家不吝指出。 ~~ 点赞 评论 收藏
  • 相关阅读:
    请问有哪些让人惊艳的数据可视化工具?
    40多行实现一个非常简单的shell
    看了还不懂b+tree的本质就来打我
    合宙ESP32C3 更换Flash调整固件教程分享
    商业地产数字化转型分析
    (原创)【B4A】一步一步入门04:编译模式、打包为APK、私钥签名
    jvs-rules(规则引擎)和jvs智能bi(自助式数据分析)9.22更新内容
    你还不知道零基础如何入门网络安全(黑客)吗?
    [蓝桥杯 2018 省 A] 航班时间
    vue3.2+ts封装axios
  • 原文地址:https://blog.csdn.net/weixin_49175501/article/details/133710563