Created
June 7, 2011 08:27
-
-
Save ymrl/1011899 to your computer and use it in GitHub Desktop.
jsのプレゼン用ファイル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(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; | |
| } | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!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