Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

66 lines (53 sloc) 2.287 kb
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Canvas Mask</title>
<style type="text/css" media="screen">
#canvas1 {
height: 300px;
width: 400px;
border: 1px solid black;
.masked {
/* -webkit-transform: rotate(10deg);*/
-webkit-mask: -webkit-canvas(canvas1);
<script type="text/javascript" charset="utf-8">
var gPageWidth = 320;
var gPageHeight = 200;
function drawPageShadow(shadowWidth)
var ctx = document.getCSSCanvasContext('2d', 'canvas1', gPageWidth, gPageHeight);
ctx.clearRect (0, 0, gPageWidth, gPageHeight);
var gradient = ctx.createLinearGradient(0, 0, shadowWidth, 0);
gradient.addColorStop(0, 'rgba(0,0,0,1)');
gradient.addColorStop(1, 'rgba(0,0,0,0)');
ctx.fillStyle = gradient;
ctx.fillRect (0, 0, shadowWidth, gPageHeight);
function redrawCanvas(event)
function onPageLoad()
window.addEventListener('load', onPageLoad, false);
<p>Hovering over the image or text should cause the element to be redrawn with a new mask</p>
<a href=""></a>
<h2>Image with mask</h2>
<img src="" width="320" height="200" alt="Clown Fish" class="masked"
<h2>Div with mask</h2>
<div class="masked" style="width: 640px" onmousemove="redrawCanvas(event)">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Jump to Line
Something went wrong with that request. Please try again.