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 7682479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:34:41+00:00 2026-05-31T18:34:41+00:00

I need help with making an image float onto the canvas in HTML5 and

  • 0

I need help with making an image float onto the canvas in HTML5 and JavaScript. I have been googling around and have not found anything. I can draw shapes on the screen but I dont know how to animate them.
I want couple of different images to float in on the canvas from different directions.
Can someone please help me with this? after 4 hours of googling all I could do was this

<script type = "Text/JavaScript">
                function Animate(){
                var canvas=document.getElementById("myCanvas"); 
                var ctx=canvas.getContext("2d"); 

                var img = new Image();

                img.onload = function ()
                {
                    ctx.drawImage(img,20,20,300,300);

                };
                img.src = "vb.png";
                }
             </script> 
    </head> 
<body> 
<canvas id="myCanvas" height="200" width="800"></canvas>
<br><button onclick="Animate();">Restart</button>

There seem to be plenty of tutorials on animating shapes but I want to load up my own pictures and have them fly in onto the canvas.

  • 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-31T18:34:43+00:00Added an answer on May 31, 2026 at 6:34 pm

    Try this very basic demo of a canvas animation:

    http://jsfiddle.net/bDQ6b/2/

    window.addEventListener('load', function () {
      var
        img = new Image,
        ctx = document.getElementById('myCanvas').getContext('2d');
    
      img.src = 'http://www.gravatar.com/avatar/a1f80339c0cef95be6dc73e0ac510d5d?s=32&d=identicon&r=PG';
      img.addEventListener('load', function () {
    
        var interval = setInterval(function() {
          var x = 0, y = 0;
    
          return function () {
            ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
            ctx.drawImage(img, x, y);
    
            x += 1;
            if (x > ctx.canvas.width) {
              x = 0;
            }
          };
        }(), 1000/40);
      }, false);
    }, false);
    

    There is a lot which could be done better though. E.g.:

    • using requestAnimationFrame instead of an interval

    • preloading the images in a more convenient way

    • using velocities and time differences (from last to current frame) instead of fixed increments

    • and many more

    but, as all this would make the example way too complicated, I’ll leave it as it is and hope you’ll read up on those topics while learning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help on making the touched areas of bitmap image transparent(seems like erasing)
i need a pointer i the right direction. I have been looking around and
I need help making AOP work. What am I missing here? <?xml version=1.0 encoding=UTF-8?>
I need help getting my head around the difference between my current OOP notion
i need help with disk_total_space function.. i have this on my code <?php $sql=select
This is for a tic tac toe game. I need help making a check
I need help with my app.yaml and url management. I have the scripts ting.py
I'm making a simple Image Debugger Visualizer. Code is below. I'm not sure if
So I'm making something for which users need to upload images from a canvas
I'm working with Javascript/jQuery and CSS to have a "background" image of a map

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.