ДС
See the Pen Untitled by Алексей Тимофеев (@aeeaakmc-the-scripter) on CodePen.
<div id="app">
<div class="hero">
<h1>Sphere</h1>
<h2>Packing</h2>
</div>
<div class="buttons">
<button type="button" id="colors-btn">
Random colors
</button>
</div>
<canvas id="webgl-canvas"></canvas>
</div>
<script>
import Spheres2Background from 'https://cdn.jsdelivr.net/npm/threejs-components@0.0.8/build/backgrounds/spheres2.cdn.min.js'
const bg = Spheres2Background(document.getElementById('webgl-canvas'), {
count: 200,
colors: [0xff0000, 0x0, 0xffffff],
minSize: 0.5,
maxSize: 1
})
const button1 = document.getElementById('colors-btn')
document.body.addEventListener('click', (ev) => {
if (ev.target !== button1) bg.togglePause()
})
button1.addEventListener('click', () => {
bg.spheres.setColors([0xffffff * Math.random(), 0xffffff * Math.random(), 0xffffff * Math.random()])
bg.spheres.light1.color.set(0xffffff * Math.random())
})
</script>
<style>
body, html, #app {
margin: 0;
width: 100%;
height: 100%;
background: radial-gradient(circle, rgba(255,255,255,1) 0%, rgba(0,0,0,0.5) 200%);
}
#app {
position: relative;
height: 100%;
font-family: "Montserrat", serif;
}
.hero {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
h1, h2 {
margin: 0;
padding: 0;
color: black;
text-transform: uppercase;
text-shadow: 0 0 20px rgba(255, 255, 255, 1);
line-height: 100%;
user-select: none;
}
h1 {
position: relative;
z-index: 2;
font-size: 100px;
font-weight: 700;
}
h2 {
font-size: 80px;
font-weight: 500;
}
#webgl-canvas {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: 1;
}
.buttons {
position: fixed;
width: 100%;
bottom: 15px;
z-index: 2;
display: flex;
justify-content: center;
align-items: center;
gap: 15px;
}
button {
font-family: "Montserrat", serif;
background: rgba(255, 255, 255, 0.5);
border-radius: 5px;
border: 1px solid grey;
padding: 4px 8px;
}
</style>