4
<!-- Last update: 2012/07/24 -->
5
<title>Canvas > Transparency Masks</title>
6
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
7
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>
8
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.base.css" type='text/css'>
9
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery.ui.theme.css" type='text/css'>
10
<style type='text/css'>
11
body {background: #e5ffcc; padding:20px;}
16
<h1>Canvas > Transparency Masks</h1>
17
<label for='radius'>Mask Radius: </label><span id='radius-value'></span><br /><br />
18
<div id='radius' style='width:300px;' />
20
<canvas id="mdi" width="512" height="512"></canvas>
23
<script type="text/javascript">
25
var canvas, context, mdi, clipImage, radius = 245;
28
canvas = document.getElementById('mdi');
29
context = canvas.getContext('2d');
31
// Image container to store MDI data
35
// When the image is loaded, draw it
36
mdi.onload = function () {
37
clipImage(mdi, radius);
41
function clipImage(image, radius) {
46
context.arc(256, 256, radius, 0, Math.PI * 2, false);
48
// Clip to the current path
51
context.drawImage(mdi, 0, 0);
57
$("#radius-value").html(radius + " pixels");
60
$( "#radius" ).slider({
64
// Slider change handler
65
slide: function(event, ui) {
66
context.clearRect(0, 0, canvas.width, canvas.height);
67
clipImage(mdi, ui.value);
68
$("#radius-value").html(ui.value + " pixels");