Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function draw() {
- var draw = false,
- context = document.getElementById('desc'),
- canvas = context.getContext('2d');
- canvas.lineWidth = 5;
- canvas.lineCap = 'round';
- context.addEventListener('mousedown', function() {
- draw = true;
- canvas.beginPath();
- }, false);
- context.addEventListener('mouseup', function() {
- draw = false;
- }, false);
- context.addEventListener('mousemove', function(e) {
- var newX = e.pageX - context.offsetLeft,
- newY = e.pageY - context.offsetTop;
- if (draw) {
- setTimeout(function() {
- canvas.lineTo(newX, newY);
- canvas.moveTo(newX, newY);
- canvas.stroke();
- }, 1);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement