Cursor · 20 of 22

Click Progress

Cursor fills on mouse down

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<div class="progress-area" id="progressArea">
  <h2>Hold Click</h2>
</div>

CSS

.progress-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;
  user-select: none;
}

.progress-canvas {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.2s;
}

JavaScript

var area = document.getElementById('progressArea');
var SIZE = 60;          // px — canvas size
var FILL_SPEED = 0.02;  // progress per frame while holding
var DRAIN_SPEED = 0.05; // progress per frame when released

var canvas = document.createElement('canvas');
canvas.width = SIZE;
canvas.height = SIZE;
canvas.className = 'progress-canvas';
area.appendChild(canvas);
var ctx = canvas.getContext('2d');
var progress = 0;
var isHolding = false;

function draw() {
  ctx.clearRect(0, 0, SIZE, SIZE);

  // Track ring
  ctx.beginPath();
  ctx.arc(SIZE / 2, SIZE / 2, 25, 0, Math.PI * 2);
  ctx.strokeStyle = 'rgba(255,255,255,0.2)';
  ctx.lineWidth = 4;
  ctx.stroke();

  // Progress arc, starting at 12 o'clock
  ctx.beginPath();
  ctx.arc(SIZE / 2, SIZE / 2, 25, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * progress);
  ctx.strokeStyle = '#7c5cff';
  ctx.lineWidth = 4;
  ctx.stroke();

  if (isHolding && progress < 1) {
    progress += FILL_SPEED;
    requestAnimationFrame(draw);
  } else if (!isHolding && progress > 0) {
    progress -= DRAIN_SPEED;
    if (progress < 0) progress = 0;
    requestAnimationFrame(draw);
  }
}

area.addEventListener('mousemove', function (e) {
  var rect = area.getBoundingClientRect();
  canvas.style.left = (e.clientX - rect.left) + 'px';
  canvas.style.top = (e.clientY - rect.top) + 'px';
});
area.addEventListener('mousedown', function () { isHolding = true; draw(); });
area.addEventListener('mouseup', function () { isHolding = false; });
area.addEventListener('mouseenter', function () {
  canvas.style.opacity = '1';
  isHolding = false;
  progress = 0;
  draw();
});
area.addEventListener('mouseleave', function () {
  canvas.style.opacity = '0';
  isHolding = false;
});