?
Solved

Getting HTML5 canvas signature to work in mobile

Posted on 2014-12-19
4
Medium Priority
?
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 40510999
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

777 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