css+js实现可调节参数的边框发光鼠标悬浮感应卡片效果代码

代码语言:html

所属分类:悬停

代码描述:css+js实现可调节参数的边框发光鼠标悬浮感应卡片效果代码,使用dat.GUI来调节效果参数。

代码标签: css js 调节 参数 边框 发光 鼠标 悬浮 感应 卡片

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

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

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

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


@font-face {
  font-family: "Geist Sans";
  src: url("//repo.bfw.wiki/bfwrepo/font/GeistVF.ttf") format("truetype");
}

:root {
	--bg: hsl(246 44% 7%);
	--border: hsl(280 10% 50% / 1);
	--card: hsl(237 36% 10%);
	--color: hsl(240 18% 80%);
	--border-width: 2px;
	--border-radius: 12px;
	--gradient: conic-gradient(from 180deg at 50% 70%,hsla(0,0%,98%,1) 0deg,#eec32d 72.0000010728836deg,#ec4b4b 144.0000021457672deg,#709ab9 216.00000858306885deg,#4dffbf 288.0000042915344deg,hsla(0,0%,98%,1) 1turn);
}

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

@property --start {
	syntax: '<number>';
	inherits: true;
	initial-value: 0;
}

body {
	background: var(--bg);
	display: grid;
	place-items: center;
	min-height: 100vh;
	font-family:  "Geist Sans", "SF Pro Text", "SF Pro Icons", "AOS Icons", "Helvetica Neue", Helvetica, Arial, sans-serif, system-ui;
	font-weight: 70;
	color: var(--color);
}

.container {
	--spread: 60;
	display: flex;
	flex-wrap: wrap;
  flex-direction: var(--direction);
	gap: calc(var(--gap) * 1px);
	margin: 0 auto;
	justify-content: center;
	place-items: center;
	position: relative;
	padding: 2rem;
}

article {
	--active: 0.15;
	--start: 0;
	height: 100%;
	background: var(--card);
	padding: 2rem;
	aspect-ratio: 330 / 400;
	border-radius: var(--border-radius);
	min-width: 280px;
	max-width: 280px;
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	position: relative;
}

article:is(:hover, :focus-visible) {
  z-index: 2;
}

.glows {
	pointer-events: none;
	position: absolute;
	inset: 0;
	filter: blur(calc(var(--blur) * 1px));
}

.glows::after,
.glows::before {
  --alpha: 0;
  content: "";
  background: var(--gradient);
  background-attachment: fixed;
  position: absolute;
	inset: -5px;
  border: 10px solid transparent;
  border-radius: var(--border-radius);
  -webkit-mask:
  	linear-gradient(hsl(0 0% 100% / var(--alpha)), hsl(0 0% 100% / var(--alpha))),
  	conic-gradient(from calc((var(--start) - (var(--spread) * 0.5)) * 1deg), transparent 0deg, white, transparent calc(var(--spread) * 1deg));
          mask:
  	linear-gradient(hsl(0 0% 100% / var(--alpha)), hsl(0 0% 100% / var(--alpha))),
  	conic-gradient(from calc((var(--start) - (var(--spread) * 0.5)) * 1deg), transparent 0deg, white, transparent calc(var(--spread) * 1deg));
  -webkit-mask-composite: source-in, xor;
          mask-composite: intersect;
  -webkit-mask-clip: padding-box, border-box;
          mask-clip: padding-box, border-box;
  opacity: var(--active);
  transition: opacity 1s;
}
article::after {
  inset: 0;
  border: var(--border-width) solid transparent;
  -webkit-mask:
  	linear-gradient(hsl(0 0% 100% / var(--alpha)), hsl(0 0% 100% / var(--alpha))),
  	conic-gradient(from calc(((var(--start) + (var(--spread) * 0.25)) - (var(--spread) * 0.5)) * 1deg), transparent 0deg, white, transparent calc(var(--spread) * 0.5deg));
          mask:
  	linear-gradient(hsl(0 0% 100% / var(--alpha)), hsl(0 0% 100% / var(--alpha))),
  	conic-gradient(from calc(((var(--start) + (var(--spread) * 0.25)) - (var(--spread) * 0.5)) * 1deg), transparent 0deg, white, transparent calc(var(--spread) * 0.5deg));
  filter: brightness(1.5);
}

article::before {
	position: absolute;
	inset: 0;
	border: 2px solid transparent;
	content: "";
	border-radius: var(--border-radius);
	pointer-events: none;
	background: var(--border);
  background-attachment: fixed;
  border-radius: var(--border-radius);
  -webkit-mask:
  	linear-gradient(hsl(0 0% 100% / 0), hsl(0 0% 100% / 0)),
  	conic-gradient(
  		from calc(((var(--start) + (var(--spread) * 0.25)) - (var(--spread) * 1.5)) * 1deg),
  		hsl(0 0% 100% / 0.15) 0deg,
  		white,
  		hsl(0 0% 100% / 0.15) calc(var(--spread) * 2.5deg));
          mask:
  	linear-gradient(hsl(0 0% 100% / 0), hsl(0 0% 100% / 0)),
  	conic-gradient(
  		from calc(((var(--start) + (var(--spread) * 0.25)) - (var(--spread) * 1.5)) * 1deg),
  		hsl(0 0% 100% / 0.15) 0deg,
  		white,
  		hsl(0 0% 100% / 0.15) calc(var(--spread) * 2.5deg));
  -webkit-mask-clip: padding-box, border-box;
          mask-clip: padding-box, border-box;
  -webkit-mask-composite: source-in, xor;
          mask-composite: intersect;
  opacity: var(--active);
  transition: opacity 1s;
}

article::after {
	--bg-size: 100%;
  --alpha: 0;
  content: "";
  pointer-events: none;
  position: absolute;
  background: var(--gradient) center center / var(--bg-size) var(--bg-size);
  background-attachment: fixed;
  border-radius: var(--border-radius);
  -webkit-mask-clip: padding-box, border-box;
          mask-clip: padding-box, border-box;
  -webkit-mask-composite: source-in, xor;
          mask-composite: intersect;
  opacity: var(--active, 0);
  transition: opacity 1s;
}

.badge {
	border: 2px solid var(--border);
	align-self: start;
	border-radius: 100px;
	padding: 0.5rem 0.7rem;
	font-size: 0.675rem;
	display: flex;
	align-items: center;
	gap: 0.25rem;
	font-weight: 50;
}

a {
	color: var(--color);
	text-decoration: none;
	opacity: 0.5;
	display: inline-block;
	align-self: start;
	transition: opacity 0.2s;
}

a:is(:hover, :focus-visible) {
	opacity: 1;
}

article h2 {
	margin: 0;
	padding: 1rem 0;
	font-weight: 100;
	font-size: 1.5rem;
}

.header {
	position: relative;
	flex: 1;
	display: flex;
	align-items: center;
}

.header svg {
	--count: 4;
	width: 106px;
}

.header svg:nth-of-type(2),
.header svg:nth-of-type(3),
.header svg:nth-of-type(4) {
	position: absolute;
	z-index: calc(var(--count) - var(--index));
	translate: calc(var(--index) * 30%) 0;
	opacity: calc(var(--count) / (2 * (var(--index) * 10)));
}

.header svg:nth-of-type(2) {
	--index: 1;
}
.header svg:nth-of-type(3) {
	--index: 2;
}
.header svg:nth-of-type(4) {
	--index: 3;
}

.badge svg {
	width: 16px;
}

.dg.ac {
  z-index: 99999 !important;
}
</style>

  
  
</head>

<body translate="no">
  <div class="container">
      <article>
        <div class="glows"></div>
        <span class="header">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
            <path fill-rule="evenodd" d="M17.303 5.197A7.5 7.5 0 006.697 15.803a.75.75 0 01-1.061 1.061A9 9 0 1121 10.5a.75.75 0 01-1.5 0c0-1.92-.732-3.839-2.197-5.303zm-2.121 2.121a4.5 4.5 0 00-6.364 6.364.75.75 0 11-1.06 1.06A6 6 0 1118 10.5a.75.75 0 01-1.5 0c0-1.153-.44-2.303-1.318-3.182zm-3.634 1.314a.75.75 0 01.82.311l5.228 7.917a.75.75 0 01-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 01-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 01-1.247-.606l.569-9.47a.75.75 0 01.554-.68z" clip-rule="evenodd" />
          </svg>
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
            <path fill-rule="evenodd" d="M17.303 5.197A7.5 7.5 0 006.697 15.803a.75.75 0 01-1.061 1.061A9 9 0 1121 10.5a.75.75 0 01-1.5 0c0-1.92-.732-3.839-2.197-5.303zm-2.121 2.121a4.5 4.5 0 00-6.364 6.364.75.75 0 11-1.06 1.06A6 6 0 1118 10.5a.75.75 0 01-1.5 0c0-1.153-.44-2.303-1.318-3.182zm-3.634 1.314a.75.75 0 01.82.311l5.228 7.917a.75.75 0 01-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 01-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 01-1.247-.606l.569-9.47a.75.75 0 01.554-.68z" clip-rule="evenodd" />
          </svg>
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
            <path fill-rule="evenodd" d="M17.303 5.197A7.5 7.5 0 006.697 15.803a.75.75 0 01-1.061 1.061A9 9 0 1121 10.5a.75.75 0 01-1.5 0c0-1.92-.732-3.839-2.197-5.303zm-2.121 2.121a4.5 4.5 0 00-6.364 6.364.75.75 0 11-1.06 1.06A6 6 0 1118 10.5a.75.75 0 01-1.5 0c0-1.153-.44-2.303-1.318-3.182zm-3.634 1.314a.75.75 0 01.82.311l5.228 7.917a.75.75 0 01-.777 1.148l-2.097-.43 1.045 3.9a.75.75 0 01-1.45.388l-1.044-3.899-1.601 1.42a.75.75 0 01-1.247-.606l.569-9.47a.75.75 0 01.554-.68z" clip-rule="evenodd" />
          </svg>
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
            <path fill-rule="evenodd" d="M17.303 5.197A7.5 7.5 0 006.697 15.803a.75.75 0 01-1.061 1.061A9 9 0 1121 10.5a.75.75 0 01-1.5 0c0-1.92-.732-3.839-2.197-5.303zm-2.121 2.121a4.5 4.5 0 00-6.364 6.364.75.75 0 11-1.06 1.06A6 6 0 1118 10.5a.75.75 0 01-1.5 0c0-1.153-.44-2.303-1.31.........完整代码请登录后点击上方下载按钮下载查看

网友评论0