动态颗粒背景,适合VUE、HTML前端显示

2024-02-05 11:44

本文主要是介绍动态颗粒背景,适合VUE、HTML前端显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

动态颗粒背景,适合做背景使用,VUE、HTML前端显示直接看效果
在这里插入图片描述
在这里插入图片描述

废话不多说直接上代码;

一、html 代码部分

<template><div id="login"><div class="container"><div class="login-form">登录表单部分</div><div class="lgBGimg"><div class="starBgc"><div class="star" v-for="(item,index) in starsCount" :key="index" ref="star"></div></div></div></div><div class="cavbg"><canvas id="spacebg"></canvas></div></div>
</template>

二、脚本部分

<script>
export default {setup() {return {starsCount:800,//数量distance:600,//间距};},mounted() {const starArr=this.$refs.starstarArr.forEach(item=>{let speed = 0.2+(Math.random()*1)let distance = this.distance+(Math.random()*300)item.style.transformOrigin=`0 0 ${distance}px`item.style.transform=`translate3d(0,0,-${distance}px) rotateY(${(Math.random()*360)}deg) rotateX(${(Math.random()*-50)}deg) scale(${speed},${speed})`});window.requestAnimFrame = (function(){return  window.requestAnimationFrame})();let canvas = document.getElementById("spacebg");let ct2d = canvas.getContext("2d");let numStars = 1800;let radius = '0.'+Math.floor(Math.random() * 9) + 1  ;let focalLength = canvas.width *2;let warp = 0;let centerX;let centerY;let stars = [];let star;let i;let animate = true;initializeStars();function executeFrame(){if(animate)requestAnimFrame(executeFrame);moveStars();drawStars();}function initializeStars(){centerX = canvas.width / 2;centerY = canvas.height / 2;stars = [];for(i = 0; i < numStars; i++){star = {x: Math.random() * canvas.width,y: Math.random() * canvas.height,z: Math.random() * canvas.width,o: '0.'+Math.floor(Math.random() * 99) + 1};stars.push(star);}}function moveStars(){for(i = 0; i < numStars; i++){star = stars[i];star.z--;if(star.z <= 0){star.z = canvas.width;}}}function drawStars(){var pixelX, pixelY, pixelRadius;if(canvas.width != window.innerWidth || canvas.width != window.innerWidth){canvas.width = window.innerWidth;canvas.height = window.innerHeight;initializeStars();}window.onresize = () => {if(canvas.width != window.innerWidth || canvas.width != window.innerWidth){canvas.width = window.innerWidth;canvas.height = window.innerHeight;initializeStars();}}if(warp==0){ct2d.fillStyle = "rgba(0,10,20,1)";// let lineGradient = ct2d.createLinearGradient (100, 10, 100, 60);//第一张图效果let lineGradient = ct2d.createLinearGradient (500, 50, 100, 600);//第二张图效果lineGradient.addColorStop(0, '#083c6f');lineGradient.addColorStop(1, '#010516');ct2d.fillStyle = lineGradient;ct2d.fillRect(0,0, canvas.width, canvas.height);}ct2d.fillStyle = "rgba(209, 255, 255, "+radius+")";for(i = 0; i < numStars; i++){star = stars[i];pixelX = (star.x - centerX) * (focalLength / star.z);pixelX += centerX;pixelY = (star.y - centerY) * (focalLength / star.z);pixelY += centerY;pixelRadius = 1 * (focalLength / star.z);ct2d.fillRect(pixelX, pixelY, pixelRadius, pixelRadius);ct2d.fillStyle = "rgba(209, 255, 255, "+star.o+")";}}executeFrame();}
};
</script>

三、样式部分代码

<style lang="less">
#login {width: 100%;height: 100%;position: relative;overflow: hidden;.container{width: 100%;height: 100%;position: relative;&:before{position: absolute;width:100%;height:100%;background:url(../../common/assets/image/background.svg);background-size: cover;opacity:0.08;display: block;content: '';z-index:2;}}.desc {width: 100% !important;text-align: center !important;color: gray !important;height: 60px !important;line-height: 60px !important;}.cavbg{position:absolute; left:0; top:0; z-index:0;}.lgBGimg{position: absolute;top:0px;left:0px;right:0px;bottom:0px;width:100%;height:100%;z-index:1;.starBgc{position: absolute;left:48%;bottom: -99px;transform: perspective(500px);transform-style: preserve-3d;perspective-origin: 50% 100%;animation: rotate 90s infinite linear;opacity:0.75;.star{width: 2px;height: 2px;background: #f7f7b8;position: absolute;top: 0;left: 0;backface-visibility: hidden;}@keyframes rotate {0%{transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);}100%{transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg);}}}}
}
</style>

效果使用了3种,分别是GIF动效、CSS3动效、2DJS动效动态元素结合,开发而成的视频视频效果

搞完手工,最后给大家放上个视频看看效果吧,欢迎留言交了讨论一下吧

动态颗粒元素背景

这篇关于动态颗粒背景,适合VUE、HTML前端显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/680805

相关文章

JAVA读取MongoDB中的二进制图片并显示在页面上

1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

vue, 左右布局宽,可拖动改变

1:建立一个draggableMixin.js  混入的方式使用 2:代码如下draggableMixin.js  export default {data() {return {leftWidth: 330,isDragging: false,startX: 0,startWidth: 0,};},methods: {startDragging(e) {this.isDragging = tr

据阿谱尔APO Research调研显示,2023年全球髓内钉市场销售额约为4.7亿美元

根据阿谱尔 (APO Research)的统计及预测,2023年全球髓内钉市场销售额约为4.7亿美元,预计在2024-2030年预测期内将以超过3.82%的CAGR(年复合增长率)增长。 髓内钉市场是指涉及髓内钉制造、分销和销售的行业。髓内钉是一种用于整形外科手术的医疗器械,用于稳定长骨骨折,特别是股骨、胫骨和肱骨。髓内钉通常由不銹钢或钛等材料制成,并插入骨的髓管中,以在愈合过程中提供结构支

vue项目集成CanvasEditor实现Word在线编辑器

CanvasEditor实现Word在线编辑器 官网文档:https://hufe.club/canvas-editor-docs/guide/schema.html 源码地址:https://github.com/Hufe921/canvas-editor 前提声明: 由于CanvasEditor目前不支持vue、react 等框架开箱即用版,所以需要我们去Git下载源码,拿到其中两个主

React+TS前台项目实战(十七)-- 全局常用组件Dropdown封装

文章目录 前言Dropdown组件1. 功能分析2. 代码+详细注释3. 使用方式4. 效果展示 总结 前言 今天这篇主要讲全局Dropdown组件封装,可根据UI设计师要求自定义修改。 Dropdown组件 1. 功能分析 (1)通过position属性,可以控制下拉选项的位置 (2)通过传入width属性, 可以自定义下拉选项的宽度 (3)通过传入classN

js+css二级导航

效果 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Con

基于Springboot + vue 的抗疫物质管理系统的设计与实现

目录 📚 前言 📑摘要 📑系统流程 📚 系统架构设计 📚 数据库设计 📚 系统功能的具体实现    💬 系统登录注册 系统登录 登录界面   用户添加  💬 抗疫列表展示模块     区域信息管理 添加物资详情 抗疫物资列表展示 抗疫物资申请 抗疫物资审核 ✒️ 源码实现 💖 源码获取 😁 联系方式 📚 前言 📑博客主页:

vue+el国际化-东抄西鉴组合拳

vue-i18n 国际化参考 https://blog.csdn.net/zuorishu/article/details/81708585 说得比较详细。 另外做点补充,比如这里cn下的可以以项目模块加公共模块来细分。 import zhLocale from 'element-ui/lib/locale/lang/zh-CN' //引入element语言包const cn = {mess

以canvas方式绘制粒子背景效果,感觉还可以

这个是看到项目中别人写好的,感觉这种写法效果还可以,就存留记录下 就是这种的背景效果。如果想改背景颜色可以通过canvas.js文件中的fillStyle值改。 附上demo下载地址。 https://download.csdn.net/download/u012138137/11249872

vue同页面多路由懒加载-及可能存在问题的解决方式

先上图,再解释 图一是多路由页面,图二是路由文件。从图一可以看出每个router-view对应的name都不一样。从图二可以看出层路由对应的组件加载方式要跟图一中的name相对应,并且图二的路由层在跟图一对应的页面中要加上components层,多一个s结尾,里面的的方法名就是图一路由的name值,里面还可以照样用懒加载的方式。 页面上其他的路由在路由文件中也跟图二是一样的写法。 附送可能存在