how to make my canvas signature tactile using touch events?
up vote
0
down vote
favorite
I am trying in vain to make my canvas tactile : i have added the touch events and e.preventdefault (to avoid scrolling) but nothing appear on my canvas (the method works perfectly on desktop). After the signature is detected, the booking button (enregistrer) is enabled (and it is the case on mobile version, despite no draw appears on the signature pad). Here is my code (what i missed??) :
initCanvas(){
this.context.clearRect(0, 0, 250, 250);/*canvas vierge*/
this.context.lineWidth = this.lineWidth;
this.canvas.style.display = "block";
this.enregistrer.style.display = "block";
}
deplacement(e) {
if(this.dragging === true){
this.context.lineTo(e.offsetX, e.offsetY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.offsetX, e.offsetY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
deplacementMobile(e){
e.preventDefault();
if(this.dragging === true){
this.context.lineTo(e.ClientX, e.clientY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.ClientX, e.ClientXY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
appuieMobile(e){
this.dragging = true;
this.deplacementMobile(e);
}
appuie(e){
this.dragging = true;
this.deplacement(e);
}
relache(){
this.dragging = false;
this.context.beginPath();/*se desengage du chemin precedent*/
}
initEvent(){
this.canvas.addEventListener("mousedown", function(e) {
this.appuie(e);
this.compteur++;
this.enregistrer.disabled = false;
}.bind(this));
this.canvas.addEventListener("mousemove", function(e) {
this.deplacement(e);
}.bind(this));
this.canvas.addEventListener("mouseup", function() {
this.relache();
}.bind(this));
this.canvas.addEventListener("touchstart", function(e) {
this.appuieMobile(e);
this.compteur++;
this.enregistrer.disabled = false;
console.log(this.compteur);
}.bind(this));
this.canvas.addEventListener("touchmove", function(e) {
this.deplacementMobile(e);
}.bind(this));
this.canvas.addEventListener("touchend", function() {
this.relache();
}.bind(this));
}
Thank u for ur help :)
javascript
add a comment |
up vote
0
down vote
favorite
I am trying in vain to make my canvas tactile : i have added the touch events and e.preventdefault (to avoid scrolling) but nothing appear on my canvas (the method works perfectly on desktop). After the signature is detected, the booking button (enregistrer) is enabled (and it is the case on mobile version, despite no draw appears on the signature pad). Here is my code (what i missed??) :
initCanvas(){
this.context.clearRect(0, 0, 250, 250);/*canvas vierge*/
this.context.lineWidth = this.lineWidth;
this.canvas.style.display = "block";
this.enregistrer.style.display = "block";
}
deplacement(e) {
if(this.dragging === true){
this.context.lineTo(e.offsetX, e.offsetY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.offsetX, e.offsetY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
deplacementMobile(e){
e.preventDefault();
if(this.dragging === true){
this.context.lineTo(e.ClientX, e.clientY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.ClientX, e.ClientXY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
appuieMobile(e){
this.dragging = true;
this.deplacementMobile(e);
}
appuie(e){
this.dragging = true;
this.deplacement(e);
}
relache(){
this.dragging = false;
this.context.beginPath();/*se desengage du chemin precedent*/
}
initEvent(){
this.canvas.addEventListener("mousedown", function(e) {
this.appuie(e);
this.compteur++;
this.enregistrer.disabled = false;
}.bind(this));
this.canvas.addEventListener("mousemove", function(e) {
this.deplacement(e);
}.bind(this));
this.canvas.addEventListener("mouseup", function() {
this.relache();
}.bind(this));
this.canvas.addEventListener("touchstart", function(e) {
this.appuieMobile(e);
this.compteur++;
this.enregistrer.disabled = false;
console.log(this.compteur);
}.bind(this));
this.canvas.addEventListener("touchmove", function(e) {
this.deplacementMobile(e);
}.bind(this));
this.canvas.addEventListener("touchend", function() {
this.relache();
}.bind(this));
}
Thank u for ur help :)
javascript
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying in vain to make my canvas tactile : i have added the touch events and e.preventdefault (to avoid scrolling) but nothing appear on my canvas (the method works perfectly on desktop). After the signature is detected, the booking button (enregistrer) is enabled (and it is the case on mobile version, despite no draw appears on the signature pad). Here is my code (what i missed??) :
initCanvas(){
this.context.clearRect(0, 0, 250, 250);/*canvas vierge*/
this.context.lineWidth = this.lineWidth;
this.canvas.style.display = "block";
this.enregistrer.style.display = "block";
}
deplacement(e) {
if(this.dragging === true){
this.context.lineTo(e.offsetX, e.offsetY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.offsetX, e.offsetY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
deplacementMobile(e){
e.preventDefault();
if(this.dragging === true){
this.context.lineTo(e.ClientX, e.clientY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.ClientX, e.ClientXY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
appuieMobile(e){
this.dragging = true;
this.deplacementMobile(e);
}
appuie(e){
this.dragging = true;
this.deplacement(e);
}
relache(){
this.dragging = false;
this.context.beginPath();/*se desengage du chemin precedent*/
}
initEvent(){
this.canvas.addEventListener("mousedown", function(e) {
this.appuie(e);
this.compteur++;
this.enregistrer.disabled = false;
}.bind(this));
this.canvas.addEventListener("mousemove", function(e) {
this.deplacement(e);
}.bind(this));
this.canvas.addEventListener("mouseup", function() {
this.relache();
}.bind(this));
this.canvas.addEventListener("touchstart", function(e) {
this.appuieMobile(e);
this.compteur++;
this.enregistrer.disabled = false;
console.log(this.compteur);
}.bind(this));
this.canvas.addEventListener("touchmove", function(e) {
this.deplacementMobile(e);
}.bind(this));
this.canvas.addEventListener("touchend", function() {
this.relache();
}.bind(this));
}
Thank u for ur help :)
javascript
I am trying in vain to make my canvas tactile : i have added the touch events and e.preventdefault (to avoid scrolling) but nothing appear on my canvas (the method works perfectly on desktop). After the signature is detected, the booking button (enregistrer) is enabled (and it is the case on mobile version, despite no draw appears on the signature pad). Here is my code (what i missed??) :
initCanvas(){
this.context.clearRect(0, 0, 250, 250);/*canvas vierge*/
this.context.lineWidth = this.lineWidth;
this.canvas.style.display = "block";
this.enregistrer.style.display = "block";
}
deplacement(e) {
if(this.dragging === true){
this.context.lineTo(e.offsetX, e.offsetY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.offsetX, e.offsetY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
deplacementMobile(e){
e.preventDefault();
if(this.dragging === true){
this.context.lineTo(e.ClientX, e.clientY);
this.context.stroke();
this.context.beginPath();
this.context.arc(e.ClientX, e.ClientXY, this.radius, 0, Math.PI*2);/*defini le 1er point en forme de cercle à chaque clic*/
this.context.fill();/*rempli le cercle*/
this.context.beginPath();
this.context.moveTo(e.offsetX, e.offsetY);
}
}
appuieMobile(e){
this.dragging = true;
this.deplacementMobile(e);
}
appuie(e){
this.dragging = true;
this.deplacement(e);
}
relache(){
this.dragging = false;
this.context.beginPath();/*se desengage du chemin precedent*/
}
initEvent(){
this.canvas.addEventListener("mousedown", function(e) {
this.appuie(e);
this.compteur++;
this.enregistrer.disabled = false;
}.bind(this));
this.canvas.addEventListener("mousemove", function(e) {
this.deplacement(e);
}.bind(this));
this.canvas.addEventListener("mouseup", function() {
this.relache();
}.bind(this));
this.canvas.addEventListener("touchstart", function(e) {
this.appuieMobile(e);
this.compteur++;
this.enregistrer.disabled = false;
console.log(this.compteur);
}.bind(this));
this.canvas.addEventListener("touchmove", function(e) {
this.deplacementMobile(e);
}.bind(this));
this.canvas.addEventListener("touchend", function() {
this.relache();
}.bind(this));
}
Thank u for ur help :)
javascript
javascript
asked Nov 11 at 11:15
moko
11
11
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248164%2fhow-to-make-my-canvas-signature-tactile-using-touch-events%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown