记录--vue+three,制作iview大波浪特效
这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助

一、效果图
具体效果可参考iview官方界面iView - 一套高质量的UI组件库
大波浪效果,使用的是three.js的官方例子,需要先安装three.js支持
npm install --save three
具体可以看 three.js examples (threejs.org)
二、代码
//添加容器
<div id="iviewUi" />
<script>
//引入three.js
import * as THREE from 'three' export default {
props: {
amountX: {
type: Number,
default: 50
},
amountY: {
type: Number,
default: 50
},
//控制点颜色
color: {
type: Number,
default: '#097bdb'
},
top: {
type: Number,
default: 350
}
},
data() {
return {
count: 0,
// 用来跟踪鼠标水平位置
mouseX: 0,
windowHalfX: null,
// 相机
camera: null,
// 场景
scene: null,
// 批量管理粒子
particles: null,
// 渲染器
renderer: null
}
},
mounted() {
this.init()
this.animate()
},
methods: {
init: function() {
const SEPARATION = 100
const SCREEN_WIDTH = window.innerWidth
const SCREEN_HEIGHT = window.innerHeight
const container = document.createElement('div')
this.windowHalfX = window.innerWidth / 2
container.style.position = 'relative'
container.style.top = `${this.top}px`
container.style.height = `${(SCREEN_HEIGHT - this.top)}px`
document.getElementById('iviewUi').appendChild(container) this.camera = new THREE.PerspectiveCamera(75, SCREEN_WIDTH / SCREEN_HEIGHT, 1, 10000)
this.camera.position.z = 1000 this.scene = new THREE.Scene() const numParticles = this.amountX * this.amountY
const positions = new Float32Array(numParticles * 3)
const scales = new Float32Array(numParticles)
// 初始化粒子位置和大小
let i = 0
let j = 0
for (let ix = 0; ix < this.amountX; ix++) {
for (let iy = 0; iy < this.amountY; iy++) {
positions[i] = ix * SEPARATION - ((this.amountX * SEPARATION) / 2)
positions[i + 1] = 0
positions[i + 2] = iy * SEPARATION - ((this.amountY * SEPARATION) / 2)
scales[j] = 1
i += 3
j++
}
} const geometry = new THREE.BufferGeometry()
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3))
geometry.addAttribute('scale', new THREE.BufferAttribute(scales, 1))
// 初始化粒子材质
const material = new THREE.ShaderMaterial({
uniforms: {
color: { value: new THREE.Color(this.color) }
},
vertexShader: `
attribute float scale;
void main() {
vec4 mvPosition = modelViewMatrix * vec4( position, 2.0 );
gl_PointSize = scale * ( 300.0 / - mvPosition.z );
gl_Position = projectionMatrix * mvPosition;
}
`,
fragmentShader: `
uniform vec3 color;
void main() {
if ( length( gl_PointCoord - vec2( 0.5, 0.5 ) ) > 0.475 ) discard;
gl_FragColor = vec4( color, 1.0 );
}
`
}) this.particles = new THREE.Points(geometry, material)
this.scene.add(this.particles) this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true })
this.renderer.setSize(container.clientWidth, container.clientHeight)
this.renderer.setPixelRatio(window.devicePixelRatio)
this.renderer.setClearAlpha(0)
container.appendChild(this.renderer.domElement) window.addEventListener('resize', this.onWindowResize, { passive: false })
document.addEventListener('mousemove', this.onDocumentMouseMove, { passive: false })
document.addEventListener('touchstart', this.onDocumentTouchStart, { passive: false })
document.addEventListener('touchmove', this.onDocumentTouchMove, { passive: false })
},
render: function() {
this.camera.position.x += (this.mouseX - this.camera.position.x) * 0.05
this.camera.position.y = 400
this.camera.lookAt(this.scene.position)
const positions = this.particles.geometry.attributes.position.array
const scales = this.particles.geometry.attributes.scale.array
// 计算粒子位置及大小
let i = 0
let j = 0
for (let ix = 0; ix < this.amountX; ix++) {
for (let iy = 0; iy < this.amountY; iy++) {
positions[i + 1] = (Math.sin((ix + this.count) * 0.3) * 100) + (Math.sin((iy + this.count) * 0.5) * 100)
scales[j] = (Math.sin((ix + this.count) * 0.3) + 1) * 8 + (Math.sin((iy + this.count) * 0.5) + 1) * 8
i += 3
j++
}
}
// 重新渲染粒子
this.particles.geometry.attributes.position.needsUpdate = true
this.particles.geometry.attributes.scale.needsUpdate = true
this.renderer.render(this.scene, this.camera)
this.count += 0.1
},
animate: function() {
requestAnimationFrame(this.animate)
this.render()
},
onDocumentMouseMove: function(event) {
this.mouseX = event.clientX - this.windowHalfX
},
onDocumentTouchStart: function(event) {
if (event.touches.length === 1) {
this.mouseX = event.touches[0].pageX - this.windowHalfX
}
},
onDocumentTouchMove: function(event) {
if (event.touches.length === 1) {
event.preventDefault()
this.mouseX = event.touches[0].pageX - this.windowHalfX
}
},
onWindowResize: function() {
this.windowHalfX = window.innerWidth / 2
this.camera.aspect = window.innerWidth / window.innerHeight
this.camera.updateProjectionMatrix()
this.renderer.setSize(window.innerWidth, window.innerHeight)
}
}
}
</script>
三、背景素材
如果不清晰可以去官方界面拿,如下图所示
本文转载于:
https://juejin.cn/post/7038372456519696421
如果对您有所帮助,欢迎您点个关注,我会定时更新技术文档,大家一起讨论学习,一起进步。

记录--vue+three,制作iview大波浪特效的更多相关文章
- nopCommerce 3.9 大波浪系列 之 使用Redis主从高可用缓存
一.概述 nop支持Redis作为缓存,Redis出众的性能在企业中得到了广泛的应用.Redis支持主从复制,HA,集群. 一般来说,只有一台Redis是不可行的,原因如下: 单台Redis服务器会发 ...
- 基于 Vue.js 之 iView UI 框架非工程化实践记要
像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引用一下,不需要就删除.故观念使然,尽管 Nuget 和 Maven ...
- 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何
基于 Vue.js 之 iView UI 框架非工程化实践记要 像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...
- nopCommerce 3.9 大波浪系列 之 使用部署在Docker中的Redis缓存主从服务
一.概述 nop支持Redis作为缓存,Redis出众的性能在企业中得到了广泛的应用.Redis支持主从复制,HA,集群. 一般来说,只有一台Redis是不可行的,原因如下: 单台Redis服务器会发 ...
- HTML5 Canvas玩转酷炫大波浪进度图
如上图所见,本文就是要实现上面那种效果. 由于最近AlloyTouch要写一个下拉刷新的酷炫loading效果.所以首选大波浪进度图. 首先要封装一下大波浪图片进度组件.基本的原理是利用Canvas绘 ...
- nopCommerce 3.9 大波浪系列 之 global.asax
一.nop的global.asax文件 nop3.9基于ASP.NET MVC 5框架开发,而ASP.NET MVC中global.asax文件包含全局应用程序事件的事件处理程序,它响应应用程序级别和 ...
- nopCommerce 3.9 大波浪系列 之 开发支持多店的插件
一.基础介绍 nop支持多店及多语言,本篇结合NivoSlider插件介绍下如何开发支持多商城的小部件. 主要接口如下: ISettingService 接口:设置接口,可实现多店配置. (点击接口介 ...
- nopCommerce 3.9 大波浪系列 之 可退款的支付宝插件(下)
一.回顾 支付宝插件源码下载地址:点击下载 上篇介绍了使用支付宝插件进行支付,全额退款,部分退款还有插件的多店铺配置,本文介绍下如何实现的. 二.前期准备 插件主要有3个功能: 多店铺插件配置 支付功 ...
- vue UI库iview源码解析(2)
上篇问题 在上篇<iview源码解析(1)>中的index.js 入口文件的源码中有一段代码有点疑惑: /** * 在浏览器环境下默认加载组件 */ // auto install if ...
- three.js的wave特效(ivew官网首页波浪特效实现)
查看效果请访问:https://521lbx.github.io/Web3D/index.html公司的好几个vue项目都是用ivew作为UI框架,所以ivew官网时不时就得逛一圈.每一次进首页都会被 ...
随机推荐
- MongoDB Security
1. Security MongoDB提供了一系列的保护措施,以保护它自身安全: 启用访问控制并实行身份验证 MongoDB支持多种身份认证机制,默认的认证机制是SCRAM 配置基于角色的访问控制 ...
- Git实战系列教程
介绍 本文详细记录了Git一系列核心概念和工作中常用的操作命令,通篇以实际出发拒绝过度理论,值得典藏:). 概念 版本管理系统 版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的 ...
- Thinkpad T14 AMD版无线网卡不可用
硬件环境: Thinkpad T14 AMD 操作系统: Windows 10家庭版 问题描述: Windows 10在后台默默做了补丁更新,导致无线网卡和蓝牙鼠标都不可用(但是有线网却是能正常工作的 ...
- 文心一言 VS 讯飞星火 VS chatgpt (202)-- 算法导论15.3 1题
一.对于矩阵链乘法问题,下面两种确定最优代价的方法哪种更高效?第一种方法是穷举所有可能的括号化方案,对每种方案计算乘法运算次数,第二种方法是运行RECURSIVE-MATRIX-CHAIN.证明你的结 ...
- 项目实战:Qt+Arm+Fpga医疗肾镜(又名内窥镜)(实时影像、冻结、拍照、白平衡、九宫格、录像、背光调整、硬件光源调整、光源手动自动调整、物理按键)
若该文为原创文章,转载请注明原文出处本文章博客地址:https://blog.csdn.net/qq21497936/article/details/111241205长期持续带来更多项目与技术分享, ...
- VUE 腾讯云 web端上传视频SDK 上传进度无法显示
上传视频官方文档:https://cloud.tencent.com/document/product/266/9239 错误信息 在本地调试可以显示视频上传进度,也可以打印到浏览器控制台.但是,发布 ...
- PMP考试计算题汇总
第6章 项目时间管理 本节术语较多.涉及的工具&技术也不少. 主要包括活动定义.活动排序.活动资源估算.活动历时估算.进度制定.进度控制6个子过程. 1.1活动定义:就是对WBS的进一步分解. ...
- Emqx高可用架构
目录 优化前架构 主要问题 haproxy问题 优化后架构 优化功能点 emq版本升级 linux系统调优 haproxy调优 测试工具 依赖安装 配置erl环境变量 安装压测软件 测试指令与结果展示 ...
- 360 数科实践:JanusGraph 到 NebulaGraph 迁移
摘要:在本文中 360 数科的周鹏详细讲解了业务从 JanusGraph 迁移到 Nebula Graph 带来的性能提升,在机器资源不到之前 JanusGraph 配置三分之一的情况下,业务性能提升 ...
- Spring Cloud跟Dubbo区别?
Spring Cloud是一个微服务框架,提供了微服务中很多功能组件,Dubbo一开始时RPC调用框架,核心是解决服务调用间的问题, Spring Cloud是一个大而全的框架,Dubbo更侧重于服务 ...