HTML,CSS,JavaScript实例——3D骰子,跨纬度蠕虫,动态登录表单。 ...

盛世宏图  金牌会员 | 2024-6-12 05:36:05 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 539|帖子 539|积分 1617


一、3D筛子


1.HTML

  1. <!--ring div starts here-->
  2. <div class="ring">
  3.   <i style="--clr:#00ff0a;"></i>
  4.   <i style="--clr:#ff0057;"></i>
  5.   <i style="--clr:#fffd44;"></i>
  6.   <div class="login">
  7.     <h2>Login</h2>
  8.     <div class="inputBx">
  9.       <input type="text" placeholder="Username">
  10.     </div>
  11.     <div class="inputBx">
  12.       <input type="password" placeholder="Password">
  13.     </div>
  14.     <div class="inputBx">
  15.       <input type="submit" value="Sign in">
  16.     </div>
  17.     <div class="links">
  18.       <a href="#">Forget Password</a>
  19.       <a href="#">Signup</a>
  20.     </div>
  21.   </div>
  22. </div>
  23. <!--ring div ends here-->
复制代码
2.CSS

  1. @import url("https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap");
  2. * {
  3.   margin: 0;
  4.   padding: 0;
  5.   box-sizing: border-box;
  6.   font-family: "Quicksand", sans-serif;
  7. }
  8. body {
  9.   display: flex;
  10.   justify-content: center;
  11.   align-items: center;
  12.   min-height: 100vh;
  13.   background: #111;
  14.   width: 100%;
  15.   overflow: hidden;
  16. }
  17. .ring {
  18.   position: relative;
  19.   width: 500px;
  20.   height: 500px;
  21.   display: flex;
  22.   justify-content: center;
  23.   align-items: center;
  24. }
  25. .ring i {
  26.   position: absolute;
  27.   inset: 0;
  28.   border: 2px solid #fff;
  29.   transition: 0.5s;
  30. }
  31. .ring i:nth-child(1) {
  32.   border-radius: 38% 62% 63% 37% / 41% 44% 56% 59%;
  33.   animation: animate 6s linear infinite;
  34. }
  35. .ring i:nth-child(2) {
  36.   border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  37.   animation: animate 4s linear infinite;
  38. }
  39. .ring i:nth-child(3) {
  40.   border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  41.   animation: animate2 10s linear infinite;
  42. }
  43. .ring:hover i {
  44.   border: 6px solid var(--clr);
  45.   filter: drop-shadow(0 0 20px var(--clr));
  46. }
  47. @keyframes animate {
  48.   0% {
  49.     transform: rotate(0deg);
  50.   }
  51.   100% {
  52.     transform: rotate(360deg);
  53.   }
  54. }
  55. @keyframes animate2 {
  56.   0% {
  57.     transform: rotate(360deg);
  58.   }
  59.   100% {
  60.     transform: rotate(0deg);
  61.   }
  62. }
  63. .login {
  64.   position: absolute;
  65.   width: 300px;
  66.   height: 100%;
  67.   display: flex;
  68.   justify-content: center;
  69.   align-items: center;
  70.   flex-direction: column;
  71.   gap: 20px;
  72. }
  73. .login h2 {
  74.   font-size: 2em;
  75.   color: #fff;
  76. }
  77. .login .inputBx {
  78.   position: relative;
  79.   width: 100%;
  80. }
  81. .login .inputBx input {
  82.   position: relative;
  83.   width: 100%;
  84.   padding: 12px 20px;
  85.   background: transparent;
  86.   border: 2px solid #fff;
  87.   border-radius: 40px;
  88.   font-size: 1.2em;
  89.   color: #fff;
  90.   box-shadow: none;
  91.   outline: none;
  92. }
  93. .login .inputBx input[type="submit"] {
  94.   width: 100%;
  95.   background: #0078ff;
  96.   background: linear-gradient(45deg, #ff357a, #fff172);
  97.   border: none;
  98.   cursor: pointer;
  99. }
  100. .login .inputBx input::placeholder {
  101.   color: rgba(255, 255, 255, 0.75);
  102. }
  103. .login .links {
  104.   position: relative;
  105.   width: 100%;
  106.   display: flex;
  107.   align-items: center;
  108.   justify-content: space-between;
  109.   padding: 0 20px;
  110. }
  111. .login .links a {
  112.   color: #fff;
  113.   text-decoration: none;
  114. }
复制代码
二、跨纬度蠕虫


1.HTML

  1. <div id="controls"></div>
复制代码
2.CSS

  1. * { margin:0; padding:0; }
  2. html, body { width:100%; height:100%; overflow: hidden; background:black;}
  3. canvas { display:block; }
  4. #controls {
  5.   z-index: 2;
  6.   margin: 20px;
  7.   position: absolute;
  8.   top: 0; left: 0;
  9.   color: white;
  10. }
复制代码
3.JS

  1. let maxPoints = 2000;
  2. let addSpeed  = 4;
  3. class Vec3{
  4.   constructor(x, y, z, r=10){
  5.     this.x = x;
  6.     this.y = y;
  7.     this.z = z;
  8.     this.r = r;
  9.     this.count = 0;
  10.   }
  11.   op(p, f){
  12.     this.x = f(this.x, p.x != undefined ? p.x : p);
  13.     this.y = f(this.y, p.y != undefined ? p.y : p);
  14.     this.z = f(this.z, p.z != undefined ? p.z : p);
  15.     return this;
  16.   }
  17.   plus  (p){return this.op(p, (a, b) => a + b)}
  18.   minus (p){return this.op(p, (a, b) => a - b)}
  19.   times (p){return this.op(p, (a, b) => a * b)}
  20.   div   (p){return this.op(p, (a, b) => a / b)}
  21.   distTo(p){return Math.hypot(this.x-p.x, this.y-p.y, this.x-p.z)}
  22.   clone  (){return new Vec3(this.x, this.y, this.z, this.r)}
  23.   updateRotation(){
  24.     let {x, y, z} = this.clone().minus(origin);
  25.     this.screenCoord = [
  26.       (x*cx - y*sx),
  27.       (y*cx + x*sx)*cy + sy*z
  28.     ];
  29.     this.depth = z*cy - sy*(y*cx + x*sx);
  30.   }
  31.   render(){
  32.     this.count++;
  33.    
  34.     let amt = this.count/maxPoints;
  35.     amt = 1-(cos(amt*addSpeed*TAU)+1)/2;
  36.     amt = pow(amt, .5);
  37.    
  38.     noFill();
  39.     stroke(this.hue, .3, 1, .05);
  40.     strokeWeight(.5);
  41.    
  42.     let r = noise((this.x+frameCount)/200, this.y/200, this.z/200)*50 + 10;
  43.     rect(...this.screenCoord, r*amt, r*amt);
  44.   }
  45. }
  46. function setup (){
  47.   pixelDensity(1);
  48.   createCanvas();
  49.   colorMode(HSB, 1, 1, 1);
  50.   rectMode(CENTER);
  51.   windowResized();
  52. }
  53. let points = [];
  54. let r = (n) => random(-n, n);
  55. let v3 = (x, y, z) => new Vec3(x, y, z);
  56. let l3 = (p1, p2, c) => new Line(p1, p2, c);
  57. let rPoint = (n) => v3(r(n), r(n), r(n));
  58. let step = 0;
  59. let d = 200;
  60. let t = 0;
  61. let p = 0;
  62. let nextPoint = () => {
  63.   step++;
  64.   d = lerp(d, 150, .001);
  65.   d += (noise(step/100, 1e6)*2-1)*.1;
  66.   d = constrain(d, 100, 200);
  67.   t += (noise(step/200, 1e7)*2-1)*.02;
  68.   p += (noise(step/200, 1e8)*2-1)*.02;
  69.   let x = d * sin(t) * cos(p);
  70.   let z = d * sin(t) * sin(p);
  71.   let y = d * cos(t);
  72.   let v = v3(x, y, z);
  73.   v.hue = ((step/3)/maxPoints)%1;
  74.   return v;
  75. }
  76. let init = () => {
  77.   points = [];
  78.   step = 0;
  79.   d = 200;
  80.   t = 0;
  81.   p = 0;
  82.   
  83.   noiseSeed(random()*1e8);
  84.   
  85.   for (let i = 0; i < maxPoints; i++){   
  86.     points.push(nextPoint());
  87.   }
  88. }
  89. let rotY = -Math.PI/4;
  90. let rotX = .4;
  91. let zoom = 2;
  92. let cx, sx, cy, sy;
  93. let near = 500;
  94. let mX = 0;
  95. let mY = 0;
  96. let origin = new Vec3(0, 0, 0);
  97. function draw(){
  98.   background(0, .3);
  99.   stroke(1);
  100.   
  101.   push();
  102.   updateCamera();
  103.   translate(width/2, height/2);
  104.   scale(zoom);
  105.   let [x, y] = origin.screenCoord;
  106.   translate(x, y);
  107.   
  108.   let n = near/(zoom*zoom);
  109.   
  110.   blendMode(ADD);
  111.   for (let i = 0; i < addSpeed; i++){
  112.     points.shift();
  113.     points.push(nextPoint());
  114.   }
  115.   points.map(p => p.updateRotation());
  116.   points.map(p => p.render());
  117.   pop();
  118. }
  119. let updateCamera = () => {
  120.   rotX += mX;
  121.   rotY += mY;
  122.   rotY = constrain(rotY, -PI, 0);
  123.   mX *= .9;
  124.   mY *= .9;
  125.   
  126.   [cx, sx, cy, sy] = [cos(rotX), sin(rotX), cos(rotY), sin(rotY)];
  127.   
  128.   rotX += .002;
  129.   
  130.   origin.updateRotation();
  131. }
  132. let pointerIsDown = false;
  133. let prevX = 0;
  134. let prevY = 0;
  135. window.addEventListener("pointerdown", evt => {
  136.   pointerIsDown = true;
  137.   prevX = evt.clientX;
  138.   prevY = evt.clientY;
  139.   console.log("pointerdown");
  140. });
  141. window.addEventListener("pointerup", evt => {
  142.   pointerIsDown = false;
  143.   console.log("pointerup");
  144. })
  145. window.addEventListener("pointermove", evt => {
  146.   if (pointerIsDown){
  147.     let [x, y] = [evt.clientX, evt.clientY];
  148.     if (prevX && prevY && x && y){
  149.       let moveX = x-prevX;
  150.       let moveY = y-prevY;
  151.       mX = -moveX/100;
  152.       mY =  moveY/100;
  153.       prevX = x;
  154.       prevY = y;
  155.     }
  156.   }
  157. });
  158. function windowResized(){
  159.   resizeCanvas(windowWidth, windowHeight);
  160.   zoom = min(width, height)*2/862;
  161.   init();
  162. }
复制代码
三、动态登录表单


1.HTML

  1. <!--ring div starts here-->
  2. <div class="ring">
  3.   <i style="--clr:#00ff0a;"></i>
  4.   <i style="--clr:#ff0057;"></i>
  5.   <i style="--clr:#fffd44;"></i>
  6.   <div class="login">
  7.     <h2>Login</h2>
  8.     <div class="inputBx">
  9.       <input type="text" placeholder="Username">
  10.     </div>
  11.     <div class="inputBx">
  12.       <input type="password" placeholder="Password">
  13.     </div>
  14.     <div class="inputBx">
  15.       <input type="submit" value="Sign in">
  16.     </div>
  17.     <div class="links">
  18.       <a href="#">Forget Password</a>
  19.       <a href="#">Signup</a>
  20.     </div>
  21.   </div>
  22. </div>
  23. <!--ring div ends here-->
复制代码
2.CSS

  1. @import url("https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap");
  2. * {
  3.   margin: 0;
  4.   padding: 0;
  5.   box-sizing: border-box;
  6.   font-family: "Quicksand", sans-serif;
  7. }
  8. body {
  9.   display: flex;
  10.   justify-content: center;
  11.   align-items: center;
  12.   min-height: 100vh;
  13.   background: #111;
  14.   width: 100%;
  15.   overflow: hidden;
  16. }
  17. .ring {
  18.   position: relative;
  19.   width: 500px;
  20.   height: 500px;
  21.   display: flex;
  22.   justify-content: center;
  23.   align-items: center;
  24. }
  25. .ring i {
  26.   position: absolute;
  27.   inset: 0;
  28.   border: 2px solid #fff;
  29.   transition: 0.5s;
  30. }
  31. .ring i:nth-child(1) {
  32.   border-radius: 38% 62% 63% 37% / 41% 44% 56% 59%;
  33.   animation: animate 6s linear infinite;
  34. }
  35. .ring i:nth-child(2) {
  36.   border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  37.   animation: animate 4s linear infinite;
  38. }
  39. .ring i:nth-child(3) {
  40.   border-radius: 41% 44% 56% 59%/38% 62% 63% 37%;
  41.   animation: animate2 10s linear infinite;
  42. }
  43. .ring:hover i {
  44.   border: 6px solid var(--clr);
  45.   filter: drop-shadow(0 0 20px var(--clr));
  46. }
  47. @keyframes animate {
  48.   0% {
  49.     transform: rotate(0deg);
  50.   }
  51.   100% {
  52.     transform: rotate(360deg);
  53.   }
  54. }
  55. @keyframes animate2 {
  56.   0% {
  57.     transform: rotate(360deg);
  58.   }
  59.   100% {
  60.     transform: rotate(0deg);
  61.   }
  62. }
  63. .login {
  64.   position: absolute;
  65.   width: 300px;
  66.   height: 100%;
  67.   display: flex;
  68.   justify-content: center;
  69.   align-items: center;
  70.   flex-direction: column;
  71.   gap: 20px;
  72. }
  73. .login h2 {
  74.   font-size: 2em;
  75.   color: #fff;
  76. }
  77. .login .inputBx {
  78.   position: relative;
  79.   width: 100%;
  80. }
  81. .login .inputBx input {
  82.   position: relative;
  83.   width: 100%;
  84.   padding: 12px 20px;
  85.   background: transparent;
  86.   border: 2px solid #fff;
  87.   border-radius: 40px;
  88.   font-size: 1.2em;
  89.   color: #fff;
  90.   box-shadow: none;
  91.   outline: none;
  92. }
  93. .login .inputBx input[type="submit"] {
  94.   width: 100%;
  95.   background: #0078ff;
  96.   background: linear-gradient(45deg, #ff357a, #fff172);
  97.   border: none;
  98.   cursor: pointer;
  99. }
  100. .login .inputBx input::placeholder {
  101.   color: rgba(255, 255, 255, 0.75);
  102. }
  103. .login .links {
  104.   position: relative;
  105.   width: 100%;
  106.   display: flex;
  107.   align-items: center;
  108.   justify-content: space-between;
  109.   padding: 0 20px;
  110. }
  111. .login .links a {
  112.   color: #fff;
  113.   text-decoration: none;
  114. }
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

正序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

盛世宏图

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表