js实现水面波纹涟漪动画效果代码
代码语言:html
所属分类:动画
代码描述:js实现水面波纹涟漪动画效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> *, *::before, *:after { box-sizing: border-box; } body { --g1-angle: 22deg; --g2-angle: -67deg; margin: 0; overflow: hidden; font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; background-image: radial-gradient( circle at center, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 1) ), linear-gradient( var(--g1-angle), rgba(40, 106, 81, 0.8), rgb(47 83 223 / 80%) ), linear-gradient( var(--g2-angle), rgba(134, 113, 19, 0.8), rgba(59, 165, 45, 0.8) ); } h1, h2, h3, p, a, button { transition: color 1000ms ease-in-out; color: rgba(255, 255, 255, 0.3); } :hover:is(a, h1, button) { transition: color 150ms ease-in-out; color: rgba(255, 255, 255, 0.8); } h1 { margin: 0; margin-bottom: clamp(1rem, 3vmin, 2rem); font-weight: 900; line-height: 0.8; text-transform: uppercase; letter-spacing: -0.25rem; font-size: clamp(5rem, 15vmin, 10rem); } .tags > * { font-size: clamp(0.8rem, 2vmin, 1rem); padding-inline: clamp(0.8rem, 5vmin, 1.2rem); padding-block: clamp(0.5rem, 2vmin, 0.8rem); border-radius: 9999px; background-color: rgba(68, 144, 225, 0.2); margin-inline-end: 1rem; margin-block-end: 1rem; } .player[data-state='stop']::before { content: 'Play '; } .player[data-state='play']::before { content: 'Stop '; } .player { border: none; cursor: pointer; inline-size: 15ch; transition: background-color 500ms ease-in-out, color 1000ms ease-in-out; } .player:is(:hover, :focus) { background-color: rgb(29, 194, 158); color: white; transition: background-color 150ms ease-in-out, background-color 300ms ease-in-out; } .player:active { transition: background-color 150ms ease-in-out, color 300ms ease-in-out; background-color: hsl(167, 74%, 35%); } .player[data-state='play'] { background-color: hsla(0, 76%, 37%, 0.644); } .text-container { padding-inline: clamp(1rem, 5vmin, 2rem); block-size: 100%; position: absolute; z-index: 1; display: flex; flex-direction: column; color: white; justify-content: center; } .circle-generator { inline-size: 100vw; block-size: 100vh; block-size: 100dvh; } .circle { --wavefront-color: 200, 50%, 40%; --wavefront-delta: 10%; --wavefront-radius: 0%; --wavefront-frequency: 10%; --wavefront-intensity: 1; --wavefront-x-pos: 0px; --wavefront-y-pos: 0px; inline-size: 100%; block-size: 100%; position: absolute; background-image: radial-gradient( circle at var(--wavefront-x-pos) var(--wavefront-y-pos), hsla(343, 67%, 52%, 0) calc(var(--wavefront-radius) - var(--wavefront-delta)), hsla(var(--wavefront-color), var(--wavefront-intensity)) var(--wavefront-radius), rgba(0, 0, 0, 0) calc(var(--wavefront-radius) + var(--wavefront-delta)) ); } </style> </head> <body > <div class="text-container"> <h1>Make Waves</h1> <div class="tags"> <!-- <a href="">#cpc-round</a> --> </div> </div> <div class="circle-generator"> </div> <script> let ctx; function buildChannel(element) { const source = ctx.createMediaElementSource(element); const gain = ctx.createGain(); const pan = ctx.createStereoPanner(); return function connectChannel(merger) { source.connect(gain).connect(pan).connect(merger).connect(ctx.destination); return { isPlaying: () => element.playing, play: () => { if (element.playing) return; element.play(); }, gain: value => gain.gain.value = value, pan: value => pan.pan.value = value }; }; } function randomRunner() { const audioElements = document.querySelectorAll('audio'); const mixer = ctx.createChannelMerger(audioElements.length); const channels = Array.from(audioElements).map(audioElement => { return buildChannel(audioElement)(mixer); }); return function player() { const control = channels[Math.random() * channels.length | 0]; if (control.isPlaying()) return player(); control.gain(0.5 * Math.random() + 0.1).........完整代码请登录后点击上方下载按钮下载查看
网友评论0