Vue3实战笔记(37)—粒子特效登录页面

62 篇文章 1 订阅
62 篇文章 1 订阅


前言

上头了,再来一个粒子特效登录页面。


一、粒子特效登录页

登录页:


<template>
   
    <div>

      <vue-particles id="tsparticles" @particles-loaded="particlesLoaded"  :options="options"  />
<form>
  <h3>Login Here</h3>

  <label for="username">Username</label>
  <input type="text" placeholder="Email or Phone" id="username">

  <label for="password">Password</label>
  <input type="password" placeholder="Password" id="password">

  <button>Log In</button>
  <div class="social">
    <div class="go"><i class="fab fa-google"></i> Google</div>
    <div class="fb"><i class="fab fa-facebook"></i> Facebook</div>
  </div>
</form><div id="tsparticles"></div>
<form>
  <h3>Login Here</h3>

  <label for="username">Username</label>
  <input type="text" placeholder="Email or Phone" id="username">

  <label for="password">Password</label>
  <input type="password" placeholder="Password" id="password">

  <button>Log In</button>
  <div class="social">
    <div class="go"><i class="fab fa-google"></i> Google</div>
    <div class="fb"><i class="fab fa-facebook"></i> Facebook</div>
  </div>
</form>

    </div>
</template>

<script setup lang="ts" name="">
let themeableContainer;

import tsParticles from "@tsparticles/vue3";


const particlesLoaded = async (container: any) => {
    console.log("Particles container loaded", container);
};
const options =

{
    fpsLimit: 60,
    fullScreen: { enable: true },
    particles: {
      number: {
        value: 50
      },
      shape: {
        type: "circle"
      },
      opacity: {
        value: 0.5
      },
      size: {
        value: 400,
        random: {
          enable: true,
          minimumValue: 200
        }
      },
      move: {
        enable: true,
        speed: 10,
        direction: "top",
        outModes: {
          default: "out",
          top: "destroy",
          bottom: "none"
        }
      }
    },
    interactivity: {
      detectsOn: "canvas",
      events: {
        resize: true
      }
    },
    style: {
      filter: "blur(50px)"
    },
    detectRetina: true,
    themes: [
      {
        name: "light",
        default: {
          value: true,
          mode: "light"
        },
        options: {
          background: {
            color: "#f7f8ef"
          },
          particles: {
            color: {
              value: ["#5bc0eb", "#fde74c", "#9bc53d", "#e55934", "#fa7921"]
            }
          }
        }
      },
      {
        name: "dark",
        default: {
          value: true,
          mode: "dark"
        },
        options: {
          background: {
            color: "#080710"
          },
          particles: {
            color: {
              value: ["#004f74", "#5f5800", "#245100", "#7d0000", "#810c00"]
            }
          }
        }
      }
    ],
    emitters: {
      direction: "top",
      position: {
        x: 50,
        y: 150
      },
      rate: {
        delay: 0.2,
        quantity: 2
      },
      size: {
        width: 100,
        height: 0
      }
    }
  }
</script>

<style lang='scss' scoped>
*,
*:before,
*:after {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
form {
  height: 520px;
  width: 400px;
  background-color: rgba(255, 255, 255, 0.13);
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
  border-radius: 10px;
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 40px rgba(8, 7, 16, 0.6);
  padding: 50px 35px;
}
form * {
  font-family: "Poppins", sans-serif;
  color: #000000;
  letter-spacing: 0.5px;
  outline: none;
  border: none;
}

@media (prefers-color-scheme: dark) {
  form * {
    color: #ffffff;
  }
}

form h3 {
  font-size: 32px;
  font-weight: 500;
  line-height: 42px;
  text-align: center;
}

label {
  display: block;
  margin-top: 30px;
  font-size: 16px;
  font-weight: 500;
}
input {
  display: block;
  height: 50px;
  width: 100%;
  background-color: rgba(255, 255, 255, 0.07);
  border-radius: 3px;
  padding: 0 10px;
  margin-top: 8px;
  font-size: 14px;
  font-weight: 300;
}

::placeholder {
  color: #1b1b1b;
}

@media (prefers-color-scheme: dark) {
  ::placeholder {
    color: #e5e5e5;
  }
}

button {
  margin-top: 50px;
  width: 100%;
  background-color: #ffffff;
  color: #080710;
  padding: 15px 0;
  font-size: 18px;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
}
.social {
  margin-top: 30px;
  display: flex;
}
.social div {
  background: red;
  width: 150px;
  border-radius: 3px;
  padding: 5px 10px 10px 5px;
  background-color: rgba(255, 255, 255, 0.27);
  color: #150f03;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .social div {
    color: #eaf0fb;
  }

  body {
    background: #000;
  }
}

.social div:hover {
  background-color: rgba(255, 255, 255, 0.47);
}
.social .fb {
  margin-left: 25px;
}
.social i {
  margin-right: 4px;
}
</style>

如果不成功仔细看第一篇文章,一步一步做,很简单的。实际效果要比图片好看多了,gif录糊了糊了。。。

在这里插入图片描述


总结

行到水穷处,坐看云起时

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的粒子群算法的 Matlab 模板: ```matlab function [x,fval]=PSO(objFun,nvar,lb,ub,options) % objFun: 目标函数的句柄 % nvar: 变量的个数 % lb: 变量的下界 % ub: 变量的上界 % options: PSO算法的选项 % 设置默认值 defaultOptions = struct('PopulationSize',50,... 'MaxIterations',100,... 'C1',2,... 'C2',2,... 'W',0.9,... 'Display','off'); % 使用传入的选项或默认选项 if exist('options','var') options = setdefault(options,defaultOptions); else options = defaultOptions; end % 提取选项中的参数 PopSize = options.PopulationSize; MaxIter = options.MaxIterations; C1 = options.C1; C2 = options.C2; W = options.W; Display = options.Display; % 初始化粒子群 X = repmat(lb,PopSize,nvar) + rand(PopSize,nvar).*(repmat(ub-lb,PopSize,1)); V = zeros(PopSize,nvar); pbest = X; pbestfit = feval(objFun,X); [gbestfit,idx] = min(pbestfit); gbest = pbest(idx,:); % PSO 算法主循环 for i=1:MaxIter % 更新粒子速度和位置 V = W*V + C1*rand(PopSize,nvar).*(pbest-X) + C2*rand(PopSize,nvar).*(repmat(gbest,PopSize,1)-X); X = X + V; % 限制粒子位置在边界内 X(X<lb) = lb(X<lb); X(X>ub) = ub(X>ub); % 更新粒子的最优位置 fit = feval(objFun,X); better = fit < pbestfit; pbestfit(better) = fit(better); pbest(better,:) = X(better,:); % 更新全局最优位置 [temp,idx] = min(pbestfit); if temp < gbestfit gbestfit = temp; gbest = pbest(idx,:); end % 显示当前迭代的结果 if strcmp(Display,'iter') fprintf('Iteration %d: Best fitness = %g\n',i,gbestfit); end end % 返回最优解和最优目标函数值 x = gbest; fval = gbestfit; end function s = setdefault(s,defaults) % 设置默认选项 fnames = fieldnames(defaults); for i=1:length(fnames) if ~isfield(s,fnames{i}) s.(fnames{i}) = defaults.(fnames{i}); end end end ``` 使用示例: ```matlab % 定义目标函数 objFun = @(x) (x(1)-2)^2 + (x(2)-3)^2; % 设置变量的下界和上界 lb = [-10,-10]; ub = [10,10]; % 设置 PSO 的选项 options.PopulationSize = 50; options.MaxIterations = 100; options.C1 = 2; options.C2 = 2; options.W = 0.9; options.Display = 'iter'; % 运行 PSO 算法 [x,fval] = PSO(objFun,2,lb,ub,options); % 显示结果 fprintf('Best solution: x1 = %g, x2 = %g\n',x(1),x(2)); fprintf('Best fitness: %g\n',fval); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值