Cursor · 17 of 22
Video Cursor
Video plays inside cursor
<div class="video-cursor-area" id="videoArea">
<h2>Video Hover</h2>
</div>
.video-cursor-area {
position: relative;
height: 240px;
display: flex;
align-items: center;
justify-content: center;
background: #12121a;
color: #f0f0f5;
overflow: hidden;
cursor: none;
font-family: sans-serif;
}
.video-float {
position: absolute;
width: 120px; height: 120px;
border-radius: 50%;
overflow: hidden;
pointer-events: none;
transform: translate(-50%, -50%) scale(0);
transition: transform 0.3s;
border: 2px solid #7c5cff;
}
.video-float video {
width: 100%; height: 100%;
object-fit: cover;
}
var area = document.getElementById('videoArea');
var VIDEO_SRC = 'https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4';
var videoFloat = document.createElement('div');
videoFloat.className = 'video-float';
var v = document.createElement('video');
v.src = VIDEO_SRC;
v.loop = true;
v.muted = true;
v.playsInline = true;
videoFloat.appendChild(v);
area.appendChild(videoFloat);
area.addEventListener('mousemove', function (e) {
var rect = area.getBoundingClientRect();
videoFloat.style.left = (e.clientX - rect.left) + 'px';
videoFloat.style.top = (e.clientY - rect.top) + 'px';
});
area.addEventListener('mouseenter', function () {
videoFloat.style.transform = 'translate(-50%, -50%) scale(1)';
v.play();
});
area.addEventListener('mouseleave', function () {
videoFloat.style.transform = 'translate(-50%, -50%) scale(0)';
v.pause();
});