I’m trying to code my own website for the first time and I’m running into some trouble. I’m following this tutorial in order to have a spotlight follow my mouse. Here’s the code. But I’d like to have a rainbow gradient across my entire homepage and have my spotlight show color as it’s moving across the page while keeping the other parts of the screen dark, more similar to how the original website, that the youtube tutorial is replicating, has shifting colors for the mouse as it moves across the screen.
My idea was to have different layers: the dark background, the "blob", the gradient, then a blur like the tutorial. The gradient wouldn’t show up against the dark background but when a white blob was beneath the gradient, then the colors would show up is my line of thinking. I’m currently at a point where it is simply the white blob and dark background. I’m wondering if this is even possible as I am thinking the issue is with the gradient’s blend modes interfering (although I don’t know if this is even the issue).
I’m also having issues having with safari. On chrome, I can get the smooth blob that tracks my mouse with a blur, however on safari, the blob either doesn’t appear or the tracking is off or the blob restarts it’s position every time I move my mouse. I know that different browsers require different things, but I was wondering if there are easier ways to make sure that both browsers can handle the site.
Also if you know another way of just having shifting colors for my blob while keeping the linear gradient that would be helpful too!
Here is my html, css, and javascript code. Thank you!
const blob = document.getElementById("blob");
window.onpointermove = event => {
const {
clientX,
clientY
} = event;
blob.animate({
left: `${clientX}px`,
top: `${clientY}px`
}, {
duration: 2500,
fill: "forwards"
});
};
body {
background-color: #222020;
height: 100vh;
margin: 0;
overflow: hidden;
position: relative;
}
#gradient-color {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: radial-gradient(50% 123.47% at 50% 50%, #00ff94 0%, #720059 100%), linear-gradient(121.28deg, #669600 0%, #ff0000 100%), linear-gradient(360deg, #0029ff 0%, #8fff00 100%), radial-gradient(100% 164.72% at 100% 100%, #6100ff 0%, #00ff57 100%), radial-gradient(100% 148.07% at 0% 0%, #fff500 0%, #51d500 100%);
background-blend-mode: screen, color-dodge, overlay, difference, normal;
z-index: 1;
opacity: 0;
}
#blob {
height: 34vmax;
aspect-ratio: 1;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border-radius: 50%;
background-color: white;
mix-blend-mode: difference;
opacity: 1;
z-index: 2;
}
#blur {
height: 100%;
width: 100%;
position: fixed;
z-index: 3;
backdrop-filter: blur(12vmax);
}
<div id="gradient-color"></div>
<div id="blob"></div>
<div id="blur"></div>
<section class="showcase">
<nav class="navbar vertical-center line line-vertical"></nav>
</section>
2
Answers
Yes there is!
The code works with use of css z-index, so you shift colors for your blob while keeping the linear gradient
Change the layers’ order, from back to front:
#gradient-color
#blob
, using::before
and::after
as a huge black rectangle and a white circle, thenmix-blend-mode: multiply
to "see through" the white circle#blur