css+div实现播放按钮变身录音机动画效果代码

代码语言:html

所属分类:动画

代码描述:css+div实现播放按钮变身录音机动画效果代码

代码标签: css div 播放 按钮 变身 录音机 动画

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

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

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

  
  
<style>
body {
  background: #fff;
  height: 100vh;
  width: 100vw;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#button-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: 1fr;
  grid-column-gap: 20px;
}
#button-row > div {
  transition: 0.3s ease-in-out;
  z-index: 1;
}
#button-row > div:last-of-type {
  z-index: 0;
}
#button-row > div:after {
  content: "";
  position: absolute;
  width: 100px;
  height: 100px;
  top: calc(50% - 50px);
  left: calc(50% - 50px);
  background: transparent;
  box-shadow: 0 0 0 1px #ccc, 0 20px 40px -15px rgba(0, 0, 0, 0.25);
  z-index: 9;
  pointer-events: none;
  transition: 0.3s ease-in-out;
}
#button-row:has(button.playing) > div:after {
  box-shadow: 0 0 0 0px #ccc, 0 20px 40px -95px rgba(0, 0, 0, 0.25);
  transform: scale(2);
}
#button-row:has(#button-container-1 button.playing) #button-container-2 {
  transform: scale(0);
}
#button-row:has(#button-container-1 button:hover) #button-container-2:after {
  box-shadow: 0 0 0 0px #ccc, 0 20px 40px -95px rgba(0, 0, 0, 0.25);
}
#button-row:has(#button-container-2 button.playing) #button-container-1 {
  transform: scale(0);
}
#button-row:has(#button-container-2 button:hover) #button-container-1:after {
  box-shadow: 0 0 0 0px #ccc, 0 20px 40px -95px rgba(0, 0, 0, 0.25);
}

#button-container-1 {
  display: flex;
  justify-content: center;
  align-items: center;
  height: auto;
  width: auto;
  position: relative;
}
#button-container-1 > div {
  width: 50px;
  height: 50px;
  background: #000;
  position: relative;
  cursor: pointer;
  border-radius: 100px;
  transition: border-radius 0.75s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0.25s, box-shadow 0.35s ease-in-out 0s;
  box-shadow: inset 0 0 0 0px #000, inset 0 0 0 -2px #fff;
  overflow: hidden;
}
#button-container-1 > div:before, #button-container-1 > div:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  z-index: 9;
  transition: opacity 0.3s ease-in-out;
  background: conic-gradient(#5454bb 0%, #b757aa 11%, #e76e91 21%, #fc9783 31%, #fdc48b 41%, #f7f1b1 51%, #ffeab8 61%, #ffe1bd 71%, #ffdcc7 80%, #b757aa 90%, #5454bb 100%);
  mix-blend-mode: darken;
  border-radius: inherit;
  pointer-events: none;
  -webkit-mask: radial-gradient(circle at center, transparent 50%, #000 25%);
  opacity: 0.75;
  animation: spin 2s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
#button-container-1 > div:after {
  opacity: 0;
  width: 150%;
  height: 150%;
  left: -25%;
  top: -25%;
  -webkit-mask: radial-gradient(circle at center, transparent 25%, #000 25%);
}
#button-container-1 > div > div {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: linear-gradient(to bottom, #222 50%, #fff 50%) 50% -50px/100% 200% no-repeat, #fff;
  transition: clip-path 0.3s cubic-bezier(0.9, 0.885, 0.32, 1), transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out, background-position 0.3s ease-in-out;
  transition-delay: 0.5s, 0.125s;
  transform: scale(0.35) translateX(12.5%);
  clip-path: polygon(0 0, 100% 50%, 100% 50%, 0% 100%);
}
#button-container-1 > div > div:before, #button-container-1 > div > div:after {
  content: "";
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background: linear-gradient(to bottom, #000 50%, transparent 50%) 0px 0px/50% 200% no-repeat, linear-gradient(to right, transparent 40%, #000 40%, #000 60%, transparent 60%) 50% 50%/100% 100% no-repeat, #fff;
  transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out, background-size 0.3s ease-in-out;
  z-index: 2;
}
#button-container-1 > div > div:before {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -25%) scaleY(0) scaleX(0.5);
  transform-origin: top;
}
#button-container-1 > div > div:after {
  z-index: 3;
  opacity: 0;
  background: linear-gradient(to right, #5454bb calc((100 / 6) * 1%), #b757aa calc((100 / 6) * 1%), #b757aa calc((100 / 6) * 2%), #e76e91 calc((100 / 6) * 2%), #e76e91 calc((100 / 6) * 3%), #fc9783 calc((100 / 6) * 3%), #fc9783 calc((100 / 6) * 4%), #fdc48b calc((100 / 6) * 4%), #fdc48b calc((100 / 6) * 5%), #f7f1b1 calc((100 / 6) * 5%), #f7f1b1 calc((100 / 6) * 6%)) 50% 50%/100% 0px, radial-gradient(circle at bottom, #5454bb 10px, #b757aa 12px, transparent 14px) 0px 100%/30px 20px repeat-x, radial-gradient(circle at bottom, #5454bb 8px, #b757aa 10px, transparent 12px) 10px 100%/30px 20px repeat-x, linear-gradient(to top, #5454bb -50%, #b757aa 11%, #e76e91 21%, #fc9783 31%, #fdc48b 41%, #f7f1b1 51%, #ffeab8 61%, #ffe1bd 71%, #ffdcc7 80%, #ffdad1 90%, #fbd5d5 100%);
  background-size: 100% 0px, 30px 20px, 30px 20px, 100% 100%;
  mix-blend-mode: darken;
  animation: float 6s linear infinite;
}
@keyframes float {
  from {
    background-position: 50% 50%, 0px calc(100% + 5px), 15px 100%, 50% 50%;
  }
  to {
    background-position: 50% 50%, -145px calc(100% + 5px), -130px 100%, 50% 50%;
  }
}
#button-container-1 > div > div span {
  position: absolute;
  width: calc((100% / 6) + 2px);
  height: 125%;
  background: #fff;
  bottom: 0;
  box-shadow: 0 0 0 1px #fff, inset 0 0 0 0px #000;
  animation: play calc(-2 * var(--timing)) ease-in-out 0 alternate;
  transform-origin: bottom;
  --delay: -0.5;
  --timing: -1.25s;
  --low: 0px;
  --mid: 0px;
  --high: 0px;
  transition: clip-path 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
  clip-path: polygon(0 100%, 100% 100%, 100% 100%, 0% 100%);
}
#button-container-1 > div > div span:nth-of-type(3n) {
  --delay: -0.15;
  --timing: -1s;
}
#button-container-1 > div > div span:nth-of-type(4) {
  --delay: -0.35;
  --timing: -0.5s;
}
@keyframes play {
  0%, 100% {
    transform: translateY(var(--high));
  }
  25%, 75% {
    transform: translateY(var(--low));
  }
  50% {
    transform: translateY(var(--mid));
  }
}
#button-container-1 > div > div span:nth-of-type(1) {
  left: calc(0% - 1px);
  animation-delay: calc(0.5s * var(--delay) + 0.5s);
}
#button-container-1 > div > div span:nth-of-type(2) {
  left: calc(16.6666666667% - 1px);
  animation-delay: calc(1s * var(--delay) + 0.5s);
}
#button-container-1 > div > div span:nth-of-type(3) {
  left: calc(33.3333333333% - 1px);
  animation-delay: calc(1.5s * var(--delay) + 0.5s);
}
#button-container-1 > div > div span:nth-of-type(4) {
  left: calc(50% - 1px);
  animation-delay: calc(2s * var(--delay) + 0.5s);
}
#button-container-1 > div > div span:nth-of-type(5) {
  left: calc(66.6666666667% - 1px);
  animation-delay: calc(2.5s * var(--delay) + 0.5s);
}
#button-container-1 > div > div span:nth-of-type(6) {
  left: calc(83.3333333333% - 1px);
  animation-delay: calc(3s * var(--delay) + 0.5s);
}
#button-container-1 button:not(.playing):hover ~ div {
  box-shadow: inset 0 0 0 5px #000, inset 0 0 0 6.5px #fff, 0 5px 15px -5px rgba(0, 0, 0, 0.75);
}
#button-container-1 button:not(.playing):hover ~ div > div:after {
  opacity: 0.75;
  transform: scale(2) translateY(-25%);
}
#button-container-1 button.playing {
  animation: noClick 2s linear 1 forwards;
}
@keyframes noClick {
  0%, 75% {
    pointer-events: none;
  }
}
#button-container-1 button.playing ~ div {
  border-radius: 0px;
  transition: border-radius 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) 0s, box-shadow 0.35s ease-in-out 0s;
  box-shadow: inset 0 0 0 2px #000, inset 0 0 0 -2px #fff, 0 5px 15px -5px rgba(0, 0, 0, 0.75);
}
#button-container-1 button.playing ~ div:before {
  opacity: 0;
}
#button-container-1 button.playing ~ div > div {
  transition: clip-path 0.3s ease-in-out, transform 0.3s ease-in-out, background-position 0.6s ease-in-out;
  background-position: 50% 0px;
  transform: scale(0.75);
  transition-delay: 0s, 0s, 0s;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
  overflow: hidden;
}
#button-container-1 button.playing ~ div > div:after {
  opacity: 0.75;
  transition-delay: 0.5s, 0.5s, 0s;
}
#button-container-1 button.playing ~ div > div > span {
  box-shadow: 0 0 0 -1px #fff, inset 0 0 0 3px #000;
  --low: 35px;
  --mid: 20px;
  --high: 10px;
  animation-iteration-count: infinite;
  transition-delay: 0.3s, 0.6s;
}
#button-container-1 button.playing:not(:hover) ~ div > div:after {
  background-size: 100% 100%, 30px 20px, 30px 20px, 100% 100%;
}
#button-container-1 button.playing:not(:hover) ~ div > div > span {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0% 100%);
}
#button-container-1 button.playing:hover ~ div {
  box-shadow: inset 0 0 0 5px #000, inset 0 0 0 7px #fff, 0 5px 15px -5px rgba(0, 0, 0, 0.75);
}
#button-container-1 button.playing:hover ~ div:after {
  opacity: 0.7.........完整代码请登录后点击上方下载按钮下载查看

网友评论0