动态颗粒背景,适合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

相关文章

springboot如何通过http动态操作xxl-job任务

《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,