tone实现可视化多节奏声音输出效果代码
代码语言:html
所属分类:多媒体
代码描述:tone实现可视化多节奏声音输出效果代码,点击左侧音乐图标开始演奏,右侧色板可调颜色。
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<style>
@charset "UTF-8";
body,
.scene, .container::after, .container::before,
.element::after,
.element::before, .container,
.element, .sound {
position: absolute;
transform-style: preserve-3d;
}
.container::after, .container::before,
.element::after,
.element::before, .container,
.element, .sound {
display: flex;
align-items: center;
justify-content: center;
}
body,
.scene {
display: grid;
place-self: center;
}
body > *,
.scene > * {
place-self: center;
}
:root {
--perspective: 400vmin;
}
*,
*::after,
*::before {
margin: 0;
border: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
width: 100vw;
overflow: hidden;
perspective: var(--perspective);
background: var(--background, #000);
}
@media screen and (orientation: portrait) {
.themes {
--test: portrait;
}
}
@media screen and (orientation: landscape) {
.themes {
--test: landscape;
}
}
.themes.horizontal {
width: 100vw;
}
.themes.vertical {
height: 100vh;
}
.themes-trigger, .themes-menu {
position: absolute;
}
.themes-trigger, .themes-select {
height: 48px;
width: 48px;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border-radius: 50%;
cursor: pointer;
}
.themes-menu {
display: flex;
overflow: hidden;
will-change: transform;
transition: transform 0.5s ease-in-out;
/* width */
/* Track */
/* Handle */
/* Handle on hover */
}
.themes-menu::-webkit-scrollbar-track {
background: transparent;
}
.themes-menu::-webkit-scrollbar-thumb {
background: var(--stroke, gray);
border-radius: 10px;
}
.themes-menu::-webkit-scrollbar-thumb:hover {
background: var(--hover, darkgray);
}
.themes.horizontal .themes-menu {
flex-wrap: nowrap;
overflow-x: scroll;
height: 78px;
width: calc(100% - 48px - 20px);
bottom: -78px;
/* width */
}
.themes.horizontal .themes-menu::-webkit-scrollbar {
height: 10px;
}
.themes.vertical .themes-menu {
flex-wrap: wrap;
overflow-y: scroll;
height: calc(100% - 48px - 20px);
width: 78px;
right: -78px;
/* width */
}
.themes.vertical .themes-menu::-webkit-scrollbar {
width: 10px;
}
.themes-select {
flex: 0 0 48px;
border: 2.5px solid var(--stroke);
background: linear-gradient(var(--background) 0% 25%, var(--stroke) 25% 50%, var(--fill) 50% 75%, var(--hover) 75% 100%);
}
.themes.horizontal .themes-select {
margin: 10px 5px;
}
.themes.vertical .themes-select {
margin: 5px 10px;
}
.themes-trigger {
right: 20px;
bottom: 10px;
background: conic-gradient(red, orange, yellow, green, blue, indigo, violet, red);
}
.themes-trigger, .themes-trigger::after {
display: flex;
justify-content: center;
align-items: center;
}
.themes-trigger::after {
content: "X";
opacity: 0;
border-radius: 50%;
height: 48px;
width: 48px;
font-size: 32px;
font-weight: bold;
color: #000;
transition: 0.35s ease-in-out;
transition-property: opacity, color;
}
.themes-trigger:hover::after {
color: #fff;
}
.themes-trigger:checked::after {
opacity: 1;
}
.themes.horizontal .themes-trigger {
right: 10px;
bottom: 20px;
}
.themes.horizontal .themes-trigger:checked + .themes-menu {
transform: translatey(-78px);
}
.themes.vertical .themes-trigger {
right: 20px;
bottom: 10px;
}
.themes.vertical .themes-trigger:checked + .themes-menu {
transform: translatex(-78px);
}
:root {
--time: 1s;
--delay: 0.0204081633s;
--elements: 7;
--animation: paused;
}
.sound {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
bottom: 10px;
left: 10px;
background: none;
cursor: pointer;
font-size: 2.5em;
}
.sound::after {
content: "🎵";
color: transparent;
text-shadow: 0 0 0 var(--fill);
}
.container::after, .container::before,
.element::after,
.element::before {
content: "";
}
.element::after {
background: var(--fill);
left: var(--position-element);
border-radius: 50%;
border: 0.25vmin solid var(--stroke);
height: 2vmin;
width: 2vmin;
-webkit-animation: rotate var(--time, 1s) var(--delay, 0s) linear infinite;
animation: rotate var(--time, 1s) var(--delay, 0s) linear infinite;
-webkit-animation-play-state: var(--animation);
animation-play-state: var(--animation);
transform-origin: calc(-1 * var(--position-element)) center;
}
.element::before {
border-radius: 50%;
border: 0.25vmin solid var(--hover);
height: var(--diameter-circle);
width: var(--diameter-circle);
opacity: 0.5;
}
.element:nth-child(1) {
--position-element: 3.875vmin;
--diameter-circle: 10vmin;
--time: 1s;
}
.element:nth-child(2) {
--position-element: 6.125vmin;
--diameter-circle: 14.5vmin;
--time: 1.0204081633s;
}
.element:nth-child(3) {
--position-element: 8.375vmin;
--diameter-circle: 19vmin;
--time: 1.0408163265s;
}
.element:nth-child(4) {
--position-element: 10.625vmin;
--diameter-circle: 23.5vmin;
--time: 1.0612244898s;
}
.element:nth-child(5) {
--position-element: 12.875vmin;
--diameter-circle: 28vmin;
--time: 1.0816326531s;
}
.element:nth-child(6) {
--position-element: 15.125vmin;
--diameter-circle: 32.5vmin;
--time: 1.1020408163s;
}
.element:nth-child(7) {
--position-element: 17.375vmin;
--diameter-circle: 37vmin;
--time: 1.1224489796s;
}
@-webkit-keyframes rotate {
100% {
transform: rotate3d(0, 0, -1, 1turn);
}
}
@keyframes rotate {
100% {
transform: rotate3d(0, 0, -1, 1turn);
}
}
</style>
</head>
<body translate="no">
<script >
function getVariableCSS(name, source = document.documentElement) {
return getComputedStyle(source).getPropertyValue(`--${name}`);
}
function setVariableCSS(name, value, source = document.documentElement) {
return source.style.setProperty(`--${name}`, value);
}
function appendChildren(children, parent = document.body) {
if (Array.isArray(children)) parent.append(...children);
else parent.append(children);
return parent;
}
function createElements(
length,
clone = document.createElement("div"),
deep = true
) {
return Array.from({ length }, () => clone.cloneNode(deep));
}
function createElement(className, tag = "div") {
const element = do.........完整代码请登录后点击上方下载按钮下载查看
网友评论0