webgl实现流体液态动画效果代码

代码语言:html

所属分类:动画

代码描述:webgl实现流体液态动画效果代码

代码标签: webgl 流体 液态 动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  
  
  
<style>
body {
  margin: 0;
  touch-action: none;
  overflow: hidden;
  display: grid;
  user-select: none;
}
canvas {
  width: 100%;
  height: auto;
  object-fit: contain;
}
body > * {
  grid-row: 1;
  grid-column: 1;
}
main {
  display: grid;
}
main > * {
  grid-row: 1;
  grid-column: 1;
}
article {
  position: relative;
  align-self: center;
  justify-self: center;
  width: 18ch;
  font: bold 20px/1 system-ui;
  color: #b5b5b5;
  text-rendering: optimizeLegibility;
}
article > h2 {
  font-size: 2em;
  opacity: 0;
  animation: fade-in 10s forwards 0s;
  margin: 0;
  line-height: 1.6;
}
article > p {
  opacity: 0;
  animation: fade-in 10s forwards 4s;
  margin: 0;
  line-height: 1.2;
}
article > p::before {
  opacity: 0;
  animation: fade-in 10s forwards 8s;
}
article > p::after {
  opacity: 0;
  animation: fade-in 10s forwards 8s;
}
article:nth-of-type(2) {
  margin-left: 5ch;
  text-align: right;
}
article:nth-of-type(3) {
  margin-left: 15ch;
}
article:nth-of-type(3) > h2 {
  text-align: center;
  line-height: 100%;
  margin: 0;
}
article:nth-of-type(3) > p {
  position: relative;
  font-size: 60px;
  line-height: 100%;
  margin: 0;
  color: #c51;
}
@media screen and (min-width: 600px) {
  article:nth-of-type(3) > p::before {
    content: "";
    position: absolute;
    height: 100vh;
    width: 100vw;
    border-top: 2px solid transparent;
    border-left: 2px solid transparent;
    border-image: linear-gradient(315deg, #b5b5b5, transparent) 1;
    left: -80px;
    top: -65px;
  }
  article:nth-of-type(3) > p::after {
    content: "";
    position: absolute;
    height: 100vh;
    width: 100vw;
    border-bottom: 2px solid transparent;
    border-right: 2px solid transparent;
    border-image: linear-gradient(135deg, #b5b5b5, transparent) 1;
    right: -80px;
    bottom: -55px;
  }
}
.hide > *,
.hide > *::before,
.hide > *::after {
  animation: fade-out 1s forwards 0s;
}
.hidden {
  visibility: hidden;
}
@keyframes fade-in {
  80% {
    transform: scale(0.8);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}
</style>


  
  
</head>

<body translate="no">
  <canvas id="canvas"></canvas>
<main class="hidden">
  <article class="hide">
    <h2>relax</h2>
    <p>you will find a way.</p>
  </article>
  <article class="hide">
    <h2>remember</h2>
    <p>life is a journey.</p>
  </article>
  <article class="hide">
    <h2>restart</h2>
    <p>NOW&hellip;</p>
  </article>
</main>
<script type="x-shader/x-fragment">#version 300 es
/*********
* made by Matthias Hurrle (@atzedent)
*/   
precision highp float;
out vec4 O;
uniform float time;
uniform vec2 resolution;
#define FC gl_FragCoord.xy
#define R resolution
#define MN min(R.x,R.y)
#define T (time+660.)
#define S smoothstep
#define N normalize
#define rot(a) mat2(cos((a)-vec4(0,11,33,0)))
float rnd(vec2 p) {
	p=fract(p*vec2(12.9898,78.233));
	p+.........完整代码请登录后点击上方下载按钮下载查看

网友评论0