console
window.onload=eventWindowLoaded();
function eventWindowLoaded() {
canvasApp();
}
function canvasApp() {
var canvas = document.getElementById('canvasOne');
var ctx = canvas.getContext('2d');
var w = canvas.width = 1020;
var h = canvas.height = 1080;
function reOffset() {
var BB = canvas.getBoundingClientRect();
offsetX = BB.left;
offsetY = BB.top;
}
var offsetX, offsetY;
reOffset();
window.onscroll = function(e) {
reOffset();
}
window.onresize = function(e) {
reOffset();
}
canvas.addEventListener('mousemove', mouseMove, false);
canvas.addEventListener('touchmove', mouseMove, false);
function draw(cx, cy, radius) {
ctx.save();
ctx.clearRect(0, 0, w, h);
var radialGradient = ctx.createRadialGradient(cx, cy, 1, cx, cy, radius);
radialGradient.addColorStop(0, 'rgba(0, 0, 0, 1)');
radialGradient.addColorStop(.65, 'rgba(0, 0, 0, 1)');
radialGradient.addColorStop(1, 'rgba(0, 0, 0, 0)');
ctx.beginPath();
ctx.fillStyle = '#000';
ctx.fillRect(0, 0, w, h);
ctx.globalCompositeOperation = 'destination-out';
ctx.arc(cx, cy, radius, 0, Math.PI * 2, false);
ctx.fillStyle = radialGradient;
ctx.fill();
ctx.restore();
}
function mouseMove(e) {
e.preventDefault();
e.stopPropagation();
mouseX = parseInt(e.clientX - offsetX);
mouseY = parseInt(e.clientY - offsetY);
draw(mouseX, mouseY, 100);
}
draw(w / 2, h / 2, 100);
}
<canvas id="canvasOne" width="800" height="800"></canvas>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
width: 100vw;
height: 100vh;
}
body {
background: url("https://farm3.staticflickr.com/2908/32764885503_1a04915b11_k.jpg") no-repeat center;
width: 100vw;
min-height: 100%;
}