Skip to content

Instantly share code, notes, and snippets.

@ymrl
Created June 7, 2011 08:27
Show Gist options
  • Save ymrl/1011899 to your computer and use it in GitHub Desktop.
Save ymrl/1011899 to your computer and use it in GitHub Desktop.
jsのプレゼン用ファイル
$(function(){
$('#drawing').css({border:'1px solid #000000'});
$('#drawing').mousedown(function(e){
var context = $(this)[0].getContext('2d');
context.beginPath();
context.moveTo(
e.pageX-$(this).offset().left,
e.pageY-$(this).offset().top
);
$(this).mousemove(function(e){
context.lineTo(
e.pageX-$(this).offset().left,
e.pageY-$(this).offset().top
);
context.stroke();
}).mouseup(function(e){
$(this).unbind('mousemove');
});
});
$('.changeColor').click(function(){
var context = $('#drawing')[0].getContext('2d');
switch($(this).text()){
case 'red':
context.strokeStyle = '#ff0000';
break;
case 'black':
context.strokeStyle = '#000000';
break;
case 'blue':
context.strokeStyle = '#0000ff';
break;
case 'green':
context.strokeStyle = '#00ff00';
break;
}
});
});
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<script src="jquery-1.6.1.min.js"></script>
<script src="drawing.js"></script>
</head>
<body>
<canvas id="drawing" width="300" height="300"></canvas>
<button class="changeColor" id="black">black</button>
<button class="changeColor" id="red">red</button>
<button class="changeColor" id="blue">blue</button>
<button class="changeColor" id="green">green</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment