// This sample shows a single canvas being displayed 3 times using bleeding edge CSS
// The top left view is a zoomed view
// The top right view is the entire canvas scaled (radar view)
// The background canvas is a 1x1 pixel view.
//
// hover the mouse over the background canvas and the zoomed view will show that
// part of the canvas.
//
// PS: Make the right area of JSFiddle wider to see the top right view.
var main = function() {
var canvasWidth = 2000;
var canvasHeight = 1500;
var workspaceWidth = 768;
var workspaceHeight = 512;
// Really?
var ctx = document.getCSSCanvasContext(
'2d', 'animation', canvasWidth, canvasHeight)
var zoomContent = document.getElementById("zoom-content");
var count = 0;
var render = function() {
var lingrad = ctx.createLinearGradient(0,0,0,canvasHeight);
lingrad.addColorStop(0, 'red');
lingrad.addColorStop(0.25, 'yellow');
lingrad.addColorStop(0.5, 'green');
lingrad.addColorStop(0.75, 'blue');
lingrad.addColorStop(1, 'purple');
ctx.fillStyle = lingrad;
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
ctx.scale(13, 13);
for (var i = 0; i < 6; ++i){
for (var j = 0; j < 6; ++j){
ctx.strokeStyle = 'rgb(0,' + Math.floor(255-42.5*i) + ',' +
Math.floor(255-42.5*j) + ')';
for (var k = 0; k < 3; ++k) {
ctx.beginPath();
ctx.arc(12.5+j*25,12.5+i*25,10 - k * 3,0,Math.PI*2,true);
ctx.stroke();
}
}
}
}
render();
var trackMouse = function(event) {
zoomContent.style.backgroundPosition =
event.offsetX / workspaceWidth * 100 + "% " +
event.offsetY / workspaceHeight * 100 + "%";
};
workspace.addEventListener('mousemove', trackMouse);
}
main();
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.