Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4119248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:03:58+00:00 2026-05-20T23:03:58+00:00

I am learning HTML5 and one of the examples that I want to learn

  • 0

I am learning HTML5 and one of the examples that I want to learn is to create 2 points on a canvas and I should be able to trace a line between the 2 points and join them, this should be done both using mouse and touch events on the mobile devices.

Are there any frameworks that provide these API or are there any examples that I can look at to get started?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:03:59+00:00Added an answer on May 20, 2026 at 11:03 pm
    window.onload=function(){
    
    var canvas = document.getElementById('canvas');
    var ctx=canvas.getContext('2d');
    var mouse={x:0,y:0}, down=false, lines=[]
    
    canvas.addEventListener("mousedown",function(e) {
                                        down=true
                                        mouse={x:e.pageX,y:e.pageY}
    
                    },false);
    
    canvas.addEventListener("mousemove",function(e) {
                             this.width=this.width
                             lines.map(function(item){
                              ctx.beginPath()
                              ctx.moveTo(item[0].x, item[0].y);
                              ctx.lineTo(item[1].x, item[1].y);
                              ctx.stroke();
                               })
                   if(down){
                       ctx.beginPath();
                       ctx.moveTo(mouse.x, mouse.y);
                       ctx.lineTo(e.pageX-this.offsetLeft, e.pageY-this.offsetTop);
                       ctx.stroke()
                       }
    
                },false);
    
    canvas.addEventListener("mouseup",function(e) {
                             down=false
                             this.width=this.width
                             lines.push([{x:mouse.x,y:mouse.y},{x:e.pageX-this.offsetLeft,y:e.pageY-this.offsetTop}])
                             lines.map(function(item){
                                  ctx.beginPath()
                                  ctx.moveTo(item[0].x, item[0].y);
                                  ctx.lineTo(item[1].x, item[1].y);
                                  ctx.stroke();
                                  })
                    },false);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been learning HTML5. One of the examples I have encountered uses an
I want to start learning HTML5 with canvas by building a simple 2d game.
I just started learning HTML5 canvas and Google App Engine's Channel API. I build
I'm in the process of learning HTML5 (and OO Javascript) and am trying to
I've been learning (X)HTML & CSS recently, and one of the main principles is
I am barely learning MySQL (moving from SQLite). I am trying to create a
I am learning php and have a book which has lots of examples and
Hi every one I'v been learning jquery for about 3 months now and I
I am confused with what prototype actually does. I am learning HTML canvas right
I'm learning Php & Mysql. I've a database(practice) with 2 table. One is Category

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.