Cursor · 06 of 22
Text Cursor
Cursor becomes text label
<div class="text-cursor-area" id="textCursorArea" data-cursor-text="VIEW">
<img src="https://picsum.photos/id/20/300/200" alt="Example">
<div class="cursor-text-label" id="cursorTextLabel"></div>
</div>
.text-cursor-area {
position: relative;
height: 240px;
display: flex;
align-items: center;
justify-content: center;
background: #12121a;
overflow: hidden;
cursor: none;
}
/* Accent disc that carries the label */
.cursor-text-label {
position: absolute;
top: 0; left: 0;
width: 60px; height: 60px;
display: flex;
align-items: center;
justify-content: center;
background: #7c5cff;
border-radius: 50%;
color: #fff;
font-family: sans-serif;
font-weight: 700;
font-size: 12px;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
opacity: 0;
transition: opacity 0.2s;
}
var area = document.getElementById('textCursorArea');
var label = document.getElementById('cursorTextLabel');
area.addEventListener('mouseenter', function () {
label.textContent = area.dataset.cursorText;
label.style.opacity = '1';
});
area.addEventListener('mousemove', function (e) {
var rect = area.getBoundingClientRect();
label.style.left = (e.clientX - rect.left) + 'px';
label.style.top = (e.clientY - rect.top) + 'px';
});
area.addEventListener('mouseleave', function () {
label.style.opacity = '0';
});