动态颗粒背景,适合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.star
    starArr.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动效动态元素结合,开发而成的视频视频效果

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

动态颗粒元素背景

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/371340.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

QXlsx Qt操作excel(1)

QXlsx 是一个用于处理Excel文件的开源C库。它允许你在你的C应用程序中读取和写入Microsoft Excel文件&#xff08;.xlsx格式&#xff09;。该库支持多种操作&#xff0c;包括创建新的工作簿、读取和写入单元格数据、格式化单元格、以及其他与Excel文件相关的功能。 关于QXlsx的…

Open CASCADE学习|拉伸

目录 1、沿方向拉伸 2、沿路径拉伸 3、变形拉伸 1、沿方向拉伸 #include <Geom_CylindricalSurface.hxx> #include <gp_Ax3.hxx> #include <GeomAPI_Interpolate.hxx> #include <BRepAdaptor_Curve.hxx> #include <BRepBuilderAPI_MakeEdge.hxx&…

Kubernetes基础(十一)-CNI网络插件用法和对比

1 CNI概述 1.1 什么是CNI&#xff1f; Kubernetes 本身并没有实现自己的容器网络&#xff0c;而是借助 CNI 标准&#xff0c;通过插件化的方式来集成各种网络插件&#xff0c;实现集群内部网络相互通信。 CNI&#xff08;Container Network Interface&#xff0c;容器网络的…

Docker 可视化工具

1、Portainer 概念介绍 Portainer是一款轻量级的应用&#xff0c;它提供了图形化界面&#xff0c;用于方便地管理Docker环境&#xff0c;包括单机环境和集群环境。 Portainer分为开源社区版&#xff08;CE版&#xff09;和商用版&#xff08;BE版/EE版&#xff09;。 Porta…

【动态规划】【树形dp】【C++算法】968监控二叉树

作者推荐 【动态规划】【字符串】【表达式】2019. 解出数学表达式的学生分数 本文涉及知识点 动态规划汇总 LeetCode:968监控二叉树 给定一个二叉树&#xff0c;我们在树的节点上安装摄像头。 节点上的每个摄影头都可以监视其父对象、自身及其直接子对象。 计算监控树的所…

16.docker删除redis缓存数据、redis常用基本命令

1.进入redis容器内部 &#xff08;1&#xff09;筛选过滤出redis容器 docker ps | grep "redis"&#xff08;2&#xff09;进入redis容器 #说明&#xff1a;d24为redis容器iddocker exec -it d24 /bin/bash2.登陆redis (1) 进入redis命令行界面 redis-cli说明&a…

elastic-job VS xxl-job

1、Elastic-job介绍 Elastic-job 是由当当网基于quartz 二次开发之后的分布式调度解决方案 &#xff0c; 由两个相对独立的子项目Elastic-Job-Lite和Elastic-Job-Cloud组成 。Elastic-Job-Lite定位为轻量级无中心化解决方案&#xff0c;使用jar包的形式提供分布式任务的协调服务…

day20网页基本标签

网页基本标签 标题标签段落标签换行标签水平线标签字体样式标签注释和特殊符号 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>网页基本标签</title> </head> <body> <!--标题…

matlab使用jdbc连接数据库

1、打包jdbc 2、在matlab安装目录下&#xff0c;进去toolbox目录下&#xff0c;新建一个对应放jdbc包的文件夹&#xff0c;加入放入的是mysql的jdbc驱动包&#xff0c;就新建一个mysql目录&#xff0c;将驱动包放入mysql目录下 3、在toolbox目录下&#xff0c;找到local目录&a…

DVI接口主机连接VGA显示器解决方案:DVI转VGA转换器DV

DVI转VGA转换器概述 DVI转VGA转换器能够将DVI数字信号转换成VGA模拟信号&#xff0c;通过VGA线缆传输给VGA显示设备使用&#xff0c;这样就能实现DVI接口主机连接VGA接口的显示器。 DVI转VGA转换器DV DVI转VGA转换器DV接口说明 DVI转VGA转换器DV接口介绍 DVI转VGA转换器连接示…

对象内存与方法调用机制

对象的内存布局 对象、字符串和数组都是引用类型&#xff0c;指向的数 我们以下面main方法部分代码片段为例&#xff1a; Cat cat new Cat(); cat.name "小白"; cat.age 12; cat.color "白色"; 首先执行mian方法&#xff0c;会在栈里创建一个独立的m…

PMP资料怎么学?PMP备考经验分享

PMP考试前大家大多都是提前备考个一两个月&#xff0c;但是有些朋友喜欢“不走寻常路”&#xff0c;并不打算去考PMP认证&#xff0c;想要单纯了解PMP&#xff0c;不管要不要考证&#xff0c;即使是仅仅学习了解一下我个人都非常支持&#xff0c;因为专业的基础的确能提高工作效…

基恩士 KV-8000 PLC通讯简单测试

1、KV-8000通讯协议 基恩士 KV-8000 PLC支持多种通讯方式&#xff0c;包括&#xff1a;OPC UA、Modbus、上位链路命令等。其中OPC UA需要对服务器和全局变量进行设置&#xff0c;Modbus需要调用功能块。默认支持的是上位链路命令&#xff0c;实际是一条条以回车换行结束的ASCII…

掌握核心:二进制运算与多进制数相互转换

常用进制数 十进制&#xff08;D&#xff09; 十进制是人们日常生活用的最多也最熟悉的一种进位计数制&#xff0c;由0、1、2、3、4、5、6、7、8、9这十个数码组成&#xff0c;基数为10。 十进制的特点是&#xff1a;逢十进一&#xff0c;借一当十 二进制&#xff08;B) 二…

【Crypto | CTF】BUUCTF 萌萌哒的八戒

天命&#xff1a;这年头连猪都有密码&#xff0c;真是奇葩&#xff0c;怪不得我一点头绪都没有 拿到软件&#xff0c;发现是.zip的压缩包&#xff0c;打不开&#xff0c;改成7z后缀名&#xff0c;打开了 发现是一张图片 也只有下面这行东西是感觉是密码了&#xff0c;又不可能…

GPT原始论文:Improving Language Understanding by Generative Pre-Training论文翻译

1 摘要 自然语理解包括文本蕴含、问题回答、语义相似性评估和文档分类等一系列多样化的任务。尽管大量未标注的文本语料库很丰富&#xff0c;但用于学习这些特定任务的标注数据却很稀缺&#xff0c;这使得基于区分性训练的模型难以充分发挥作用。我们展示了通过在多样化的未标…

Java split 分割字符串避坑

使用split进行字符串分割时需要注意2点 1、特殊字符作为分隔符时需要使用\\进行转义(如\\ -> \\\\; | -> \\| ) 特殊字符 .$|()[{^?*\\ 例如对"|"分隔 未转义 String str "01|02|03"; String[] strArr str.split("|");System.out.…

前端登陆加密解决方案

项目背景 环食药烟草的数据下载模块中&#xff0c;需要判断用户在进行数据下载时是进行了登录操作&#xff0c;如果没有登录要跳转登陆页面&#xff0c;输入账号和密码进行登录。 使用场景 项目中需要前端书写登录页面&#xff0c;用户输入账号密码&#xff0c;前端获取到用…

leetcode 3.无重复字符的最长字串(滑动窗口) (C++)DAY2

文章目录 1.题目示例提示 2.解答思路3.实现代码结果 4.总结 1.题目 给定一个字符串 s &#xff0c;请你找出其中不含有重复字符的 最长子串 的长度。 示例 示例 1: 输入: s “abcabcbb” 输出: 3 解释: 因为无重复字符的最长子串是 “abc”&#xff0c;所以其长度为 3。 示…

ChatGPT Plus如何升级?信用卡付款失败怎么办?如何使用信用卡升级 ChatGPT Plus?

ChatGPT Plus是OpenAI提供的一种高级服务&#xff0c;它相较于标准版本&#xff0c;提供了更快的响应速度、更强大的功能&#xff0c;并且用户可以优先体验到新推出的功能。 尽管许多用户愿意支付 20 美元的月费来订阅 GPT-4&#xff0c;但在实际支付过程中&#xff0c;特别是…
最新文章