js+css实现鼠标悬停文本菜单多个产品图片跟随效果代码

代码语言:html

所属分类:悬停

代码描述:js+css实现鼠标悬停文本菜单多个产品图片跟随效果代码,可通过tweakpane修改参数。

代码标签: js css 鼠标 悬停 文本 菜单 多个 产品 图片跟 随效

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

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

<head>
  <meta charset="UTF-8">
  
  
<style>
/* @import 'normalize.css' layer(normalize); */
@import url('https://unpkg.com/normalize.css') layer(normalize);
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200..700&display=swap');

@layer normalize, base, demo, positioning, anchoring, boxes, tweaks, images, debug;

@layer debug {
  [data-debug='true'] {
    img {
      --opacity: 0.2;
    }
    .holder {
      outline: 0.1em dashed hsl(10 100% 50% / 0.2);
      outline-offset: 0.1em;
    }
    .box {
      outline: dashed red 0.1em;
    }
    .holding {
      outline: hsl(10 100% 50% / 0.5) dashed 0.1em;
      outline-offset: 0.1em;
    }
    .scope {
      outline: red dashed 0.1em;
      outline-offset: 0em;
    }
  }
}

@layer images {
  .box img {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
       object-fit: cover;
    border-radius: 0.2em;
    grid-area: 1 / 1;
    opacity: 0;
    transition: opacity 0.25s 0s;
    mix-blend-mode: plus-lighter;
    box-shadow: 0px 0.2px 0.2px var(--shadow-color),
      0.1px 1.4px 1.6px -0.4px var(--shadow-color),
      0.1px 2.7px 3px -0.7px var(--shadow-color),
      0.2px 4.4px 5px -1.1px var(--shadow-color),
      0.3px 7px 7.9px -1.4px var(--shadow-color),
      0.4px 10.9px 12.3px -1.8px var(--shadow-color),
      0.6px 16.6px 18.7px -2.1px var(--shadow-color),
      0.9px 24.4px 27.5px -2.5px var(--shadow-color);
  }
  .box {
    display: grid;
    isolation: isolate;
  }

  .container:has(li:nth-of-type(1):hover) .box img:nth-of-type(1),
  .container:has(li:nth-of-type(2):hover) .box img:nth-of-type(2),
  .container:has(li:nth-of-type(3):hover) .box img:nth-of-type(3),
  .container:has(li:nth-of-type(4):hover) .box img:nth-of-type(4),
  .container:has(li:nth-of-type(5):hover) .box img:nth-of-type(5) {
    opacity: var(--opacity, 1);
    z-index: 2;
    transition-delay: 0s;
  }
}

@layer tweaks {
  :root {
    --elastic-out: linear(
      0 0%,
      0.6832 7.89%,
      0.9171 11.07%,
      1.0251 12.99%,
      1.1058 14.9%,
      1.1619 16.86%,
      1.1945 18.91%,
      1.2024 20.02%,
      1.2043 21.18%,
      1.1907 23.72%,
      1.1598 26.27%,
      1.0604 32.59%,
      1.0172 35.84%,
      0.9839 39.49%,
      0.967 43.26%,
      0.9639 45.77%,
      0.9661 48.59%,
      0.9963 60.54%,
      1.0054 67.42%,
      1 100%
    );
  }
  .box {
    transform: translate(calc(var(--x) * 1%), calc(var(--y) * 1%))
      rotate(calc(var(--r) * 1deg))
      translate(
        calc(var(--px, 0) * var(--prx, 0%)),
        calc(var(--py, 0) * var(--pry, 0%))
      );
    transition: translate 0.2s, scale 0.2s, transform 0.8s var(--elastic-out);
  }
  .holder:nth-of-type(1) .box {
    --prx: -80%;
    --pry: 15%;
  }
  .holder:nth-of-type(2) .box {
    --prx: 25%;
    --pry: -35%;
  }
  .holder:nth-of-type(3) .box {
    --prx: 30%;
    --pry: 35%;
  }
}

@layer boxes {
  .holder {
    width: 2lh;
    aspect-ratio: 1;
    position: absolute;
    left: 50%;
    top: 50%;
  }

  .box {
    width: 100%;
    height: 100%;
    scale: 0;
  }

  [data-use-anchor='false'] {
    .holder:nth-of-type(1) {
      --offset-x: calc(-150% - (var(--start-width) * 0.5px));
      translate: var(--offset-x) -50%;
    }

    .holder:nth-of-type(2) {
      --offset-x: calc(50% + (var(--start-width) * 0.5px));
      translate: var(--offset-x) -50%;
    }

    .holder:nth-of-type(3) {
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0