svg+gsap实现液态融合粘稠状菜单导航条交互效果代码

代码语言:html

所属分类:菜单导航

代码描述:svg+gsap实现液态融合粘稠状菜单导航条交互效果代码

代码标签: svg gsap 液态 融合 粘稠状 菜单 导航条 交互

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

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

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

  
  
  
<style>
body, html {
    margin: 0;
    padding: 0;
}

canvas#gooey-canvas,
svg#gooey-overlay {
    position: fixed;
    top: 0;
    left: 0;
}

svg#gooey-overlay .menu-item {
    cursor: pointer;
}

svg#gooey-overlay .menu-item use {
    stroke: #000066;
}

svg#gooey-overlay .menu-item:hover use {
    stroke: hotpink;
}
</style>

  
  
</head>

<body >
  <div class="wrapper">
    <canvas id="gooey-canvas"></canvas>
    <svg id="gooey-overlay" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="6">
        <defs>
            <symbol id="icon-user" viewBox="0 0 100 100">
                <g>
                    <circle cx="46.3" cy="30.5" r="20.7"/>
                    <path d="M70.4,58.4a31.8,31.8,0,0,1,7.8,21"/>
                    <path d="M14.3,79.4a31.6,31.6,0,0,1,7.8-20.9"/>
                </g>
            </symbol>
            <symbol id="icon-settings" viewBox="0 0 100 100">
                <g>
                    <path d="M71.5,51.3a28.4,28.4,0,0,0,.5-5.1,25.7,25.7,0,0,0-.8-6.2l8.9-5.9a35.4,35.4,0,0,0-10-14.9l-8.9,6a24,24,0,0,0-6.1-3.3V11.2a38.2,38.2,0,0,0-9-1.1,36.8,36.8,0,0,0-8.9,1.1V21.9a27.3,27.3,0,0,0-6.7,3.7l-9-5.7A35.5,35.5,0,0,0,11.8,35l9.1,5.6a26.9,26.9,0,0,0,0,11.3l-8.9,6a35,35,0,0,0,9.8,14.9l8.8-5.9a26.4,26.4,0,0,0,6.6,3.6V81.2a36.8,36.8,0,0,0,8.9,1.1,38.2,38.2,0,0,0,9-1.1V70.5a27,27,0,0,0,7-4l9.1,5.7A37.5,37.5,0,0,0,80.6,57ZM46.2,61.5A15.3,15.3,0,1,1,61.5,46.2,15.4,15.4,0,0,1,46.2,61.5Z"/>
                </g>
            </symbol>
            <symbol id="icon-msg" viewBox="0 0 100 100">
                <g>
                    <path d="M81.9,43.2c0,12.9-16,23.4-35.7,23.4-6.3,0-10-.4-15.2-2.2-1.8-.7-17.5,9.1-19.1,8.2s6-14.9,3.9-17.2a17.4,17.4,0,0,1-5.3-12.2c0-13,16-23.5,35.7-23.5S81.9,30.2,81.9,43.2Z"/>
                </g>
            </symbol>
        </defs>
        <g class="balls">
        </g>
    </svg>
</div>

<script type="x-shader/x-fragment" id="vertShader">
    precision mediump float;

    varying vec2 vUv;
    attribute vec2 a_position;

    void main() {
        vUv = .5 * (a_position + 1.);
        gl_Position = vec4(a_position, 0., 1.);
    }
</script>

<script type="x-shader/x-fragment" id="fragShader">
    precision mediump float;

    varying vec2 vUv;
    uniform float u_time;
    uniform float u_ratio;
    uniform float u_max_y;
    uniform vec2 u_pointer;
    uniform float u_click_t;
    uniform vec3 u_drops_pos_x;
    uniform vec3 u_drops_pos_y;

    vec3 permute(vec3 x) { return mod(((x*34.0)+1.0)*x, 289.0); }
    float snoise(vec2 v){
        const vec4 C = vec4(0.211324865405187, 0.366025403784439,
        -0.577350269189626, 0.024390243902439);
        vec2 i = floor(v + dot(v, C.yy));
        vec2 x0 = v - i + dot(i, C.xx);
        vec2 i1;
        i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
        vec4 x12 = x0.xyxy + C.xxzz;
        x12.xy -= i1;
        i = mod(i, 289.0);
        vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0))
        + i.x + vec3(0.0, i1.x, 1.0));
        vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy),
        dot(x12.zw, x12.zw)), 0.0);
        m = m*m;
        m = m*m;
        vec3 x = 2.0 * fract(p * C.www) - 1.0;
        vec3 h = abs(x) - 0.5;
        vec3 ox = floor(x + 0.5);
        vec3 a0 = x - ox;
        m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
        vec3 g;
        g.x = a0.x * x0.x + h.x * x0.y;
        g.yz = a0.yz * x12.xz + h.yz * x12.yw;
        return 130.0 * dot(m, g);
    }

    float get_point_shape(vec2 uv, vec2 pos) {
        float width = 1.9 * (u_drops_pos_x[2] - u_drops_pos_x[0]) / 3.;

        float point_uv_y = (1. / pos.y - (1. / pos.y) * (uv.y - .05));

        vec2 dist = vec2(uv.x * u_ratio, uv.y) - vec2(pos.x * u_ratio, 1. - pos.y);
        float l = length(dist);
        l = max(0., l);
        l /= u_max_y;
        l *= u_ratio;
        width += .1 * pow(l, -.7);

        float c = smoothstep(pos.x - .5 * width, pos.x, uv.x);
        c *= smoothstep(pos.x + .5 * width, pos.x, uv.x);
        c *= smoothstep(1. - pos.y - .5 * u_ratio * width, 1. - pos.y, uv.y);

        c = pow(c, 10.);

        return c;
    }


    void main() {
        vec2 uv = vUv;
        uv.y -= .03;

        float noise_speed = .25;
        float width = .2;
        float shape = 0.;

        float mid_shape = smoothstep(0. - .7 * width, u_drops_pos_x[1] - u_drops_pos_x[0], uv.x - u_drops_pos_x[0]) - smoothstep(u_drops_pos_x[1], u_drops_pos_x[2] + .5 * width, uv.x);
        mid_shape = pow(mid_shape, 1.5);
        mid_shape *= 2.6 * (1. - (1. - uv.y) / max(u_drops_pos_y[0], max(u_drops_pos_y[1], u_drops_pos_x[2])));

        float top_shape = (1. - (1. - uv.y) / u_max_y);
        top_shape = pow(top_shape, 3.);
        vec2 noise_uv = uv;
        noise_uv.x /= width;
        noise_uv.x *= .7;
        noise_uv.y += noise_speed * u_time;
        float noise = snoise(noise_uv);
        top_shape -= .2 * noise;

        noise_uv.x *= .1;
        noise = snoise(noise_uv);
        top_shape -= .2 * noise;

        shape += .5 * mid_shape;
        shape += top_shape;
        shape = 5. * pow(shape, 7.);

        for (int i = 0; i < 3; i++) {
            float column = get_point_shape(vUv, vec2(u_drops_pos_x[i], u_drops_pos_y[i]));
            shape += column;
        }

        float border_limit = .4;
        float border = smoothstep(border_limit, border_limit + .1, shape);
        float contour = border - smoothstep(border_limit, border_limit + .25, shape);

        shape = clamp(shape, 0., 2.);
        shape = .4 + pow(shape, .2);

        vec3 purple = vec3(0.780, 0.474, 0.816);
        vec3 yellow = vec3(0.996, 0.675, 0.368);
        vec3 blue = vec3(0.296, 0.753, 0.784);

        vec3 color = mix(blue, purple, (.5 + .1 * sin(u_time)) * shape);

        vec2 p = uv - u_pointer;
        p.x *= u_ratio;
        float pl = (1. - min(1., length(p)));
        pl = pow(pl, 10.);
        pl *= (1. + u_click_t);
        pl += .4 * noise;
        color = mix(color, yellow, pl + .1 * shape);

        color -= .2 * contour;
        color += (.2 * pl) * contour;

        color *= shape;

        gl_FragColor = vec4(color, border);
    }
</script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/gsap.3.9.1.js"></script>
      <script  >
const canvasEl = document.querySelector("#gooey-canvas");
const svgEl = document.querySelector("#gooey-overlay");
const svgBallsEl = svgEl.querySelector(".balls");

const params = {
  pageContentMaxWidth: 800,
  btnPixelRadius: 43,
  widthPixel: 300,
  heightPixel: 250,
  clickPower: 0 };


const buttons = [
{ name: "user", pos: { x: 0, y: 0 } },
{ name: "settings", pos: { x: 0, y: 0 } },
{ name: "msg", pos: { x: 0, y: 0 } }];


const pointer = {
  x: 0, y: 0,
  tx: 0, ty: 0 };


createOverlay();
resizeOverlay();

const uniforms = {
  timeLocation: null,
  dropsPosYLocation: null,
  dropsPosXLocation: null,
  pointerLocation: null,
  ratioLocation: null,
  clickLocation: null };

const gl = initShader();
resizeCanvas();

setupAnimation();

window.addEventListener("resize", () => {
  resizeOverlay();
  resizeCanvas();.........完整代码请登录后点击上方下载按钮下载查看

网友评论0