js+css实现卡片悬浮背景滑块跟随动画效果代码

代码语言:html

所属分类:悬停

代码描述:js+css实现卡片悬浮背景滑块跟随动画效果代码

代码标签: js css 卡片 悬浮 背景 滑块 跟随 动画

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

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

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

  
<style>

* {
  box-sizing: border-box;
}

:root {
  --bg: hsl(0 0% 2%);
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--bg);
}

main {
  width: 60ch;
  max-width: 100%;
}

body {
  font-family: 'Geist', arial;
  font-weight: 100;
}

ul {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  list-style-type: none;
  padding: 0;
  margin: 0;
}

li {
  padding: 1rem;
  list-style-type: none;
}

ul::after {
  border-radius: 1rem;
  content: "";
  position: absolute;
  background: hsl(0 0% 10%);
  pointer-events: none;
  z-index: -2;
  inset:
    calc(var(--top) * 1px)
    calc(100% - (var(--right) * 1px))
    calc(100% - (var(--bottom) * 1px))
    calc(var(--left) * 1px);
  transition: inset 0.2s;
}

ul[data-enhanced]:hover {
  --active: 1;
}
ul[data-enhanced]::after {
  opacity: var(--active, 0);
  transition: opacity 0.2s, inset 0.2s 0.2s;
}
ul[data-enhanced]:hover::after {
  transition: opacity 0.2s 0.2s, inset 0.2s;
}

@supports(anchor-name: --anchor) {
  li:nth-of-type(1) article { anchor-name: --develop; }
  li:nth-of-type(2) article { anchor-name: --preview; }
  li:nth-of-type(3) article { anchor-name: --ship; }
  li:nth-of-type(4) article { anchor-name: --profit; }

  :root { --anchor: --develop; }
  :root:has(li:nth-of-type(1):hover) { --anchor: --develop; }
  :root:has(li:nth-of-type(2):hover) { --anchor: --preview; }
  :root:has(li:nth-of-type(3):hover) { --anchor: --ship; }
  :root:has(li:nth-of-type(4):hover) { --anchor: --profit; }  

  ul::a.........完整代码请登录后点击上方下载按钮下载查看

网友评论0