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

  • Home
  • SEARCH
  • 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 9311053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:16:05+00:00 2026-06-19T01:16:05+00:00

I have a function that draw something on a canvas after triggering the if

  • 0

I have a function that draw something on a canvas after triggering the if statement. I would like to know how to clear the canvas after it has been remove from the the coordinate(outside the if statement), I’m not sure how to go about this.

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript">
            function startCanvas() {
                var c = document.getElementById("myCanvas");
                var ctx = c.getContext("2d");

                var one = c.getContext("2d");
                var two = c.getContext("2d");
                var three = c.getContext("2d");
                var four = c.getContext("2d");
                var five = c.getContext("2d");
                var clearCanvas = false;

                var image = new Image();
                var imageone = new Image();

                image.onload = function () {
                    ctx.drawImage(image, 69, 50);

                    //draw a circle
                    one.beginPath();
                    one.arc(180, 90, 10, 0, Math.PI * 2, true);
                    one.closePath();
                    one.fill();

                    two.beginPath();
                    two.arc(155, 138, 10, 0, Math.PI * 2, true);
                    two.closePath();
                    two.fill();

                    three.beginPath();
                    three.arc(160, 180, 10, 0, Math.PI * 2, true);
                    three.closePath();
                    three.fill();

                    four.beginPath();
                    four.arc(257, 210, 10, 0, Math.PI * 2, true);
                    four.closePath();
                    four.fill();

                    five.beginPath();
                    five.arc(238, 235, 10, 0, Math.PI * 2, true);
                    five.closePath();
                    five.fill();
                };

                image.src = 'denmark.jpg';

                c.addEventListener(
                    'mousemove',
                    function (e) {
                        if ((e.x >= 170 && e.x <= 190) && (e.y >= 80 && e.y <= 100)) {
                            alert('this is a test');
                        }
                    },
                    false);

                c.addEventListener(
                    'mousemove',
                    function (e) {
                        if ((e.x >= 145 && e.x <= 190) && (e.y >= 128 && e.y <= 148)) {
                            ctx.font = "30px Arial";
                            ctx.fillText("Hello World", 400, 20);
                            ctx.drawImage(imageone, 400, 60);
                            imageone.src = 'alborg.jpg';
                        } else if ((e.x < 145 && e.x < 190) && (e.y > 128 && e.y < 148)) {
                            ctx.clearRect(0, 0, 400, 60);
                        }
                    },
                    false);

                c.addEventListener(
                    'mousemove',
                    function (e) {
                        if ((e.x >= 150 && e.x <= 190) && (e.y >= 170 && e.y <= 190)) {
                            alert('also work');
                        }
                    },
                    false);

                c.addEventListener(
                    'mousemove',
                    function (e) {
                        if ((e.x >= 247 && e.x <= 290) && (e.y >= 200 && e.y <= 220)) {
                            alert('ok');
                        }
                    },
                    false);

                c.addEventListener(
                    'mousemove',
                    function (e) {
                        if ((e.x >= 228 && e.x <= 290) && (e.y >= 225 && e.y <= 245)) {
                            alert('yes');
                        }
                    },
                    false);
            }
        </script>
    </head>
    <body onload="startCanvas()">
        <canvas id="myCanvas" width="600" height="600">Your browser does not support the HTML5 canvas tag.</canvas>
    </body>
</html>
  • 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-06-19T01:16:06+00:00Added an answer on June 19, 2026 at 1:16 am

    To clear the canvas of your “Hello World” and “alborg.jpg”, use this: ctx.clearRect(400,0,200,600)

    Example code:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title></title>
    
    <script type="text/javascript">
        function startCanvas() {
            var c = document.getElementById("myCanvas");
            var ctx = c.getContext("2d");
    
            var one = c.getContext("2d");
            var two = c.getContext("2d");
            var three = c.getContext("2d");
            var four = c.getContext("2d");
            var five = c.getContext("2d");
            var clearCanvas = false;
    
            var image = new Image();
            var imageone = new Image();
    
            image.onload = function () {
                ctx.drawImage(image, 69, 50);
    
                //draw a circle
                one.beginPath();
                one.arc(180, 90, 10, 0, Math.PI * 2, true);
                one.closePath();
                one.fill();
    
                two.beginPath();
                two.arc(155, 138, 10, 0, Math.PI * 2, true);
                two.closePath();
                two.fill();
    
                three.beginPath();
                three.arc(160, 180, 10, 0, Math.PI * 2, true);
                three.closePath();
                three.fill();
    
                four.beginPath();
                four.arc(257, 210, 10, 0, Math.PI * 2, true);
                four.closePath();
                four.fill();
    
                five.beginPath();
                five.arc(238, 235, 10, 0, Math.PI * 2, true);
                five.closePath();
                five.fill();
            };
    
            image.src = 'coffee.png';
    
    
         c.addEventListener('mousemove',
         function (e) {
             if ((e.x >= 170 && e.x <= 190) && (e.y >= 80 && e.y <= 100)) {
                 alert('this is a test');
             }
         }
         , false);
    
    
         c.addEventListener('mousemove',
         function (e) {
          if ((e.x >= 145 && e.x <= 190) && (e.y >= 128 && e.y <= 148)) {
              ctx.font = "30px Arial";
              ctx.fillText("Hello World", 400, 20);
              ctx.drawImage(imageone, 400, 60);
              imageone.src = 'house-icon.png';
          } else if ((e.x < 145 && e.x < 190) && (e.y > 128 && e.y < 148)) {
          //
          //
          // HERE IS THE CHANGE TO MAKE YOUR CODE WORK !!!
          //
          // Use this to clear only the "Hello World" and "alborg.jpg"
          //
          //
                    ctx.clearRect(400,0,200,600);
          //
          //
          //
                }
            }
            , false);
    
    
          c.addEventListener('mousemove',
          function (e) {
               if ((e.x >= 150 && e.x <= 190) && (e.y >= 170 && e.y <= 190)) {
                   alert('also work');
               }
           }
           , false);
    
           c.addEventListener('mousemove',
              function (e) {
                  if ((e.x >= 247 && e.x <= 290) && (e.y >= 200 && e.y <= 220)) {
                      alert('ok');
                  }
              }
              , false);
    
            c.addEventListener('mousemove',
            function (e) {
                if ((e.x >= 228 && e.x <= 290) && (e.y >= 225 && e.y <= 245)) {
                    alert('yes');
                }
            }
            , false);
    
        }
    </script>
    </head>
    <body onload="startCanvas()">
    <canvas id="myCanvas" width="600" height="600";">
    Your browser does not support the HTML5 canvas tag.</canvas>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that draw an image on graphics: private void DrawSmallImage(Graphics g)
Inside my Controller i have function that runs after user clicks on item, which
I have a function that counts the amount of visits a page has, and
I'm new to HTML5/Canvas/Game programming, but have been tinkering around with it after reading
I have some functions that use opengl to draw lines on the screen (health
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have a function that returns two values in a list. Both values need
I have a function that takes an input string and then runs the string

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.