Solved

Getting HTML5 canvas signature to work in mobile

Posted on 2014-12-19
4
125 Views
Last Modified: 2015-12-02
Wondering how to get the signature part of this app

http://karrtransportation.com/employment/home/

to work when on a mobile phone, currently it just scrolls around when you try to sign.

Many Thanks!
0
Comment
Question by:Greg Alexander
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40510999
0
 
LVL 43

Accepted Solution

by:
Rob earned 500 total points
ID: 40511224
Here's a very simple demo that you should be able to easily incorporate into your site:

http://jsbin.com/cozaxu/1/edit?js,output

<canvas id="canvas" width="683" height="200" style="width: 683px; height: 200px; border: 1px solid rgb(0, 0, 0);">Canvas is not supported</canvas>

$(function() {
  var bDraw = false;
  var old = {};
  $('#canvas').on('touchstart', function(e) {
    e.preventDefault();
    //console.dir(e.originalEvent);
    old = {
      x: e.originalEvent.touches[0].clientX,
      y: e.originalEvent.touches[0].clientY
    };
    bDraw = true;

  });
  $('#canvas').on('touchend', function(e) {
    e.preventDefault();
    bDraw = false;
  });
  $('#canvas').on('touchmove', function(e) {
    e.preventDefault();
    var _from = old;
    var _to = {
      x: e.originalEvent.touches[0].clientX,
      y: e.originalEvent.touches[0].clientY      
    };
    old = _to;
    if (bDraw) {
      draw(_from, _to);
    }
  });

});

function draw(f, t) {
  var c = document.getElementById("canvas");
  var ctx = c.getContext("2d");
  ctx.moveTo(f.x,f.y);
  ctx.lineTo(t.x,t.y);
  ctx.stroke();
}

Open in new window

0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question