css+js实现可调整参数的下拉菜单选择立体展开效果代码

代码语言:html

所属分类:其他

代码描述:css+js实现可调整参数的下拉菜单选择立体展开效果代码,使用tweakpane来调节参数。

代码标签: css js 调整 参数 下拉 菜单 选择

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


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

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

  <script type="module">
  if (!("anchorName" in document.documentElement.style)) {
    window.UPDATE_ANCHOR_ON_ANIMATION_FRAME = true;
    import("//repo.bfw.wiki/bfwrepo/js/module/css-anchor-positioning.js");
  }
</script>

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

body {
	display: grid;
	place-items: center;
	min-height: 100vh;
	font-family: 'SF Pro Text', 'SF Pro Icons', 'AOS Icons', 'Helvetica Neue',
		Helvetica, Arial, sans-serif, system-ui;
}


body::before {
  --size: 60px;
  --line: hsl(0 0% 0% / 0.15);
  content: '';
  height: 100vh;
  width: 100vw;
  position: fixed;
  background: linear-gradient(
        90deg,
        var(--line) 1px,
        transparent 1px var(--size)
      )
      50% 50% / var(--size) var(--size),
    linear-gradient(var(--line) 1px, transparent 1px var(--size)) 50% 50% /
      var(--size) var(--size);
  -webkit-mask: linear-gradient(-15deg, transparent 30%, white);
          mask: linear-gradient(-15deg, transparent 30%, white);
  top: 0;
  transform-style: flat;
  pointer-events: none;
  z-index: -1;
}

/* Anchor styles are managed inline inside the head */
#pop {
	inset: unset;
	/*  display: block;*/
	width: 180px;
	border: 0;
	padding: 0;
	background: transparent;
	transform-style: preserve-3d;
	overflow: visible;
	font-weight: 300;
}

body > [popovertarget] {
  anchor-name: --trigger;
}
#pop {
  left: anchor(--trigger left);
  top: calc(anchor(--trigger bottom) + 0.5rem);
}

:root {
	--speed: .5s;
	--accent: hsl(30 80% 50%);
  --ease: ease-out;
	accent-color: var(--accent);
}

@supports((-webkit-animation-timing-function: linear(1, 1)) or (animation-timing-function: linear(1, 1))) {
  :root {
    --ease: linear(
      0, 0.0012 14.95%, 0.0089 22.36%,
      0.0297 28.43%, 0.0668 33.43%,
      0.0979 36.08%, 0.1363 38.55%,
      0.2373 43.07%, 0.3675 47.01%,
      0.5984 52.15%, 0.7121 55.23%,
      0.8192 59.21%, 0.898 63.62%,
      0.9297 66.23%, 0.9546 69.06%,
      0.9733 72.17%, 0.9864 75.67%,
      0.9982 83.73%, 1
    );
  }
}

#pop.\:popover-open .popover__content ul {
	-webkit-animation: drop calc(var(--speed) * 1s) var(--ease);
	        animation: drop calc(var(--speed) * 1s) var(--ease);
}

#pop:popover-open .popover__content ul {
	-webkit-animation: drop calc(var(--speed) * 1s) var(--ease);
	        animation: drop calc(var(--speed) * 1s) var(--ease);
}

#pop.\:popover-open .popover__content::after,
#pop.\:popover-open .popover__content {
	-webkit-animation: open calc(var(--speed) * 1s) var(--ease);
	        animation: open calc(var(--speed) * 1s) var(--ease);
}

#pop:popover-open .popover__content::after,
#pop:popover-open .popover__content {
	-webkit-animation: open calc(var(--speed) * 1s) var(--ease);
	        animation: open calc(var(--speed) * 1s) var(--ease);
}

#pop.\:popover-open .popover__content::before {
	-webkit-animation: slam calc(var(--speed) * 1s) var(--ease) both;
	        animation: slam calc(var(--speed) * 1s) var(--ease) both;
}
#pop:popover-open .popover__content::before {
	-webkit-animation: slam calc(var(--speed) * 1s) var(--ease) both;
	        animation: slam calc(var(--speed) * 1s) var(--ease) both;
}

.popover__content::before {
	--blur: 1rem;
	content: '';
	position: absolute;
	inset: var(--blur) calc(var(--blur) * -1.15) calc(var(--blur) * -3)
		calc(var(--blur) * -1.15);
	background: hsl(0 0% 0% / 0.2);
	-webkit-clip-path: polygon(
		0 0,
		100% 0,
		calc(100% + var(--blur)) calc(100% + var(--blur)),
		calc(var(--blur) * -3) calc(100% + var(--blur))
	);
	        clip-path: polygon(
		0 0,
		100% 0,
		calc(100% + var(--blur)) calc(100% + var(--blur)),
		calc(var(--blur) * -3) calc(100% + var(--blur))
	);
	z-index: -2;
	transform-origin: 50% 0;
	filter: blur(var(--blur));
	border-radius: 1rem 1rem 6px 6px;
	/*	mask: linear-gradient(transparent, white);*/
}

.popover__content::after {
	content: "";
	z-index: -1;
  background: hsl(0 0% 98%);
	position: absolute;
	inset: 0;
	border-radius: 6px;
	box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
		0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

@-webkit-keyframes open {
	0% {
		opacity: 0;
	}
}

@keyframes open {
	0% {
		opacity: 0;
	}
}

@-webkit-keyframes slam {
	to {
		opacity: 0;
		inset: 0;
	}
}

@keyframes slam {
	to {
		opacity: 0;
		inset: 0;
	}
}

@-webkit-keyframes drop {
	0% {
		rotate: x calc(var(--rotation, 30) * 1deg);
	}
}

@keyframes drop {
	0% {
		rotate: x calc(var(--rotation, 30) * 1deg);
	}
}

[popovertarget] {
	font-size: 0.875rem;
	display: flex;
	gap: 0.25rem;
	align-items: center;
	padding: 0.5rem 0.75rem;
	background: hsl(0 0% 98%);
	border-radius: 6px;
	border: 1px solid hsl(0 0% 60%);
	outline-color: var(--accent);
	width: 160px;
	cursor: pointer;
  color: hsl(0 0% 10%);
}

[popovertarget] svg {
	width: 24px;
	height: 1rem;
	opacity: 0.5;
}

[popovertarget] span:first-of-type {
	opacity: 0.5;
}

[popovertarget] span:last-of-type {
	flex: 1;
	text-align: left;
}

.popover__content {
	position: relative;
	transform-style: preserve-3d;
	perspective: calc(var(--perspective, 500) * 1px);
  max-height: 40vh;
}

.popover__content ul {
	border: 1px solid hsl(0 0% 90%);
	border-radius: 6px;
	padding: 0.25rem;
	background: hsl(0 0% 98%);
	transform-origin: 50% 0;
	margin: 0;
	padding: 0;
	list-style-type: none;
	display: grid;
	gap: 0.25rem;
	transform-style: preserve-3d;
  max-height: 40vh;
  overflow: auto;
  scrollbar-color: var(--accent) transparent;
  scrollbar-width: thin;
}

.popover__content button {
	width: 100%;
	display: flex;
	border: 0;
	background: transparent;
	padding: 0;
	margin: 0;
	font-weight: 300;
	color: hsl(0 0% 10%);
	cursor: pointer;
	position: relative;
	overflow: hidden;
	padding: 0.5rem;
	font-size: 0.875rem;
	justify-content: space-between;
  outline-color: transparent;
  outline: none;
}

.popover__content button svg {
	stroke: var(--accent);
	stroke-width: 3;
	display: none;
}

.popover__content button[data-selected=true] svg {
	display: block;
}

.popover__content button:is(:hover, :focus-visible) {
	--intent: 1;
}

.popover__content button::after {
	content: '';
	position: absolute;
	inset: 0;
	background: hsl(0 0% 80%/ 0.25);
	opacity: var(--intent, 0);
}


/* Social */
.bear-link {
  color: canvasText;
  position: fixed;
  top: 1rem;
  left: 1rem;
  width: 48px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  opacity: 0.8;
}

:where(.x-link, .bear-link):is(:hover, :focus-visible) {
  opacity: 1;
}
.bear-link svg {
  width: 75%;
}

div.tp-dfwv {
  width: 300px;
}
</style>

  
</head>

<body>
  <button popovertarget="pop">
      <span>Style:</span>
      <span>Minimalist</span>
      <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="M8.25 15 12 18.75 15.75 15m-7.5-6L12 5.25 15.75 9"
        />
      </svg>
    </button>
    <div id="pop" popover="auto">
      <div class="popover__content">
        <ul>
          <li>
            <button
              data-value="Minimalist"
           .........完整代码请登录后点击上方下载按钮下载查看

网友评论0