It seems that the issue lies in the mix-blend-mode: difference
. By removing it, the display appears correctly:
var crs = document.querySelector('.cursor');
document.addEventListener('mousemove', (e) => {
var ds1 = e.clientX - crs.clientWidth / 2;
var ds2 = e.clientY - crs.clientHeight / 2;
crs.setAttribute('style', `position: fixed;left:${ds1}px;top:${ds2}px;z-index:999;`);
})
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
cursor: none;
scroll-behavior: smooth;
}
.cursor {
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #000 !important;
/* mix-blend-mode: difference; */
transition: padding .4s;
position: fixed;
z-index: 999;
pointer-events: none;
}
#home-vd {
position: relative;
z-index: 10;
}
<video class="video" id="home-vd" src="https://www.w3schools.com/tags/movie.mp4"></video>
<div class="cursor" id="cursor">
</div>
Although I'm not well-versed in blend modes, it seems that using difference
as the foreground can cause it to disappear on any background color:
var crs = document.querySelector('.cursor');
document.addEventListener('mousemove', (e) => {
var ds1 = e.clientX - crs.clientWidth / 2;
var ds2 = e.clientY - crs.clientHeight / 2;
crs.setAttribute('style', `position: fixed;left:${ds1}px;top:${ds2}px;z-index:999;`);
})
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
cursor: none;
scroll-behavior: smooth;
}
.cursor {
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #000 !important;
mix-blend-mode: difference;
transition: padding .4s;
position: fixed;
z-index: 999;
pointer-events: none;
}
#home-vd {
position: relative;
z-index: 10;
}
.block {
height: 300px;
width: 300px;
background-color: magenta;
color: white;
}
<h1 class="block">hi hi hi hi</h1>
<div class="cursor" id="cursor">
</div>
To achieve a more usable result, try using a different color:
var crs = document.querySelector('.cursor');
document.addEventListener('mousemove', (e) => {
var ds1 = e.clientX - crs.clientWidth / 2;
var ds2 = e.clientY - crs.clientHeight / 2;
crs.setAttribute('style', `position: fixed;left:${ds1}px;top:${ds2}px;z-index:999;`);
})
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Roboto', sans-serif;
cursor: none;
scroll-behavior: smooth;
}
.cursor {
width: 25px;
height: 25px;
border-radius: 50%;
background-color: #555 !important;
mix-blend-mode: difference;
transition: padding .4s;
position: fixed;
z-index: 999;
pointer-events: none;
}
#home-vd {
position: relative;
z-index: 10;
}
.block {
height: 300px;
width: 300px;
background-color: magenta;
color: white;
}
<h1 class="block">hi hi hi hi</h1>
<div class="cursor" id="cursor">
</div>
If you're curious about the color math behind blend modes, perhaps someone more knowledgeable in the field could provide insights.