div+css模仿mac电脑dock底部菜单栏悬浮动画效果代码

代码语言:html

所属分类:菜单导航

代码描述:div+css模仿mac电脑dock底部菜单栏悬浮动画效果代码

代码标签: div css 模仿 mac 电脑 dock 底部 菜单栏 悬浮 动画

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

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

<head>
  <meta charset="UTF-8">
  <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/open-props.css">

  <link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/open-props.normalize.min.css">
  
<style>

:root {
  --lerp-0: 1; /* === sin(90deg) */
  --lerp-1: calc(sin(30deg));
  --lerp-2: calc(sin(20deg));
  --lerp-3: calc(sin(10deg));
  --lerp-4: 0;
}

*,
*:after,
*:before {
  box-sizing: border-box;
}

h1 {
  position: fixed;
  top: var(--size-4);
  right: var(--size-4);
  margin: 0;
  color: var(--gray-0);
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-family:  'Google Sans', sans-serif, system-ui;
  background: var(--gradient-6);
}

/*:root {
  --lerp-0: 1;
  --lerp-1: 0.5625;
  --lerp-2: 0.25;
  --lerp-3: 0.0625;
  --lerp-4: 0;
}*/

.block:nth-of-type(1){--hue: 10;}
.block:nth-of-type(2){--hue: 210;}
.block:nth-of-type(3){--hue: 290;}
.block:nth-of-type(4){--hue: 340;}
.block:nth-of-type(5){--hue: 30;}
.block:nth-of-type(6){--hue: 220;}
.block:nth-of-type(7){--hue: 320;}
.block:nth-of-type(8){--hue: 280;}
.block:nth-of-type(9){--hue: 240;}

.blocks {
  display: flex;
  list-style-type: none;
  padding: var(--size-2);
  border-radius: var(--radius-3);
  gap: var(--size-4);
  background: hsl(0 0% 100% / 0.5);
  box-shadow: 
    0 2px 0 0 hsl(0 0% 100% / 0.5) inset,
    0 2px 0 0 hsl(0 0% 25% / 0.5);
  align-items: center;
  justify-content: center;
  align-content: center;
  -webkit-backdrop-filter: blur(10px);
          backdrop-filter: blur(10px);
}

.blocks:hover {
  --show: 1;
}

.block {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  align-content: center;
  transition: all 0.2s;
  flex: calc(0.2 + (var(--lerp, 0) * 1.5));
  max-width: 100px;
  position: relative;
}

.block:after {
  content: '';
  width: 5%;
  aspect-ratio: 1;
  background: var(--text-1);
  position: absolute;
  bottom: 10%;
  left: 50%;
  border-radius: var(--radius-3);
  transform: translate(-50%, -50%);
  z-index: -1;
}

.block:before {
  content: '';
  position: absolute;
  width: calc(100% + var(--size-4));
  bottom: 0;
  aspect-ratio: 1 / 2;
  left: 50%;
  transition: transform 0.2s;
  transform-origin: 50% 100%;
  transform: translateX(-50%) scaleY(var(--show, 0));
  z-index: -1;
}

.block .block__item {
  transition: outline 0.2s;
  outline: transparent var(--size-1) solid;
}

.block svg {
  width: 80%;
  transition: all 0.2s;
  stroke: var(--gray-1);
}

:is(.block:focus-visible) .block__item {
  outline: var(--gray-1) var(--size-1) solid;
  border-radius: var(--radius-3);
}

.block {
  outline: none;
}

.block__item {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-2);
  background:
    linear-gradient(hsl(0 0% 100% / 0.1), transparent),
    hsl(var(--hue, 10) 70% 60%);
  display: grid;
  place-items: center;
  transition: all 0.2s;
  box-shadow:
    0 2px 0 0 hsl(0 0% 100% / 0.5) inset,
    0 2px 0 0 hsl(0 0% 25% / 0.5);
  transform-origin: 50% 100%;
  position: relative;
  translate: 0 calc(var(--lerp) * -75%);
}

/*@media(prefers-color-scheme: dark) {
}*/
body {
  background: var(--gradient-23);
}
.blocks {
  background: hsl(0 0% 0% / 0.5);
}


:is(.block:hover, .block:focus-visible) {
  --lerp: var(--lerp-0);
  z-index: 5;
}
.block:has( + :is(.block:hover, .block:focus-visible)),
:is(.block:hover, .block:focus-visible) + .block {
  --lerp: var(--lerp-1);
  z-index: 4;
}
.block:has( + .block + :is(.block:hover, .block:focus-visible)),
:is(.block:hover, .block:focus-visible) + .block + .block {
  --lerp: var(--lerp-2);
  z-index: 3;
}
.block:has( + .block + .block + :is(.block:hover, .block:focus-visible)),
:is(.block:hover, .block:focus-visible) + .block + .block + .block {
  --lerp: var(--lerp-3);
  z-index: 2;
}
.block:has( + .block + .block + .block + :is(.block:hover, .block:focus-visible)),
:is(.block:hover, .block:focus-visible) + .block + .block + .block + .block {
  --lerp: var(--lerp-4);
  z-index: 1;
}
</style>


  
  
</head>

<body>
  <nav class="blocks">
  <a href="#" class="block">
    <div class="block__item">
      <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
        <path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75l3 3m0 0l3-3m-3 3v-7.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
      </svg>
    </div>
  </a>
  <a href="#" class="block">
    <div class="block__item">
      <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
        <path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 01-1.043 3.296 3.745 3.745 0 01-3.296 1.043A3.745 3.745 0 0112 21c-1.268 0-2.39-.63-3.068-1.593a3.74.........完整代码请登录后点击上方下载按钮下载查看

网友评论0