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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:54:32+00:00 2026-05-23T08:54:32+00:00

I wanted a rectangle to move horizontally..However, the rectangle is not animating..How do I

  • 0

I wanted a rectangle to move horizontally..However, the rectangle is not animating..How do I fix this?

<script type="text/javascript">
var interval = 10;
var x=0;
var y=0;
var rect = null;
var context ;
var canvas;

function Rectangle(x, y, width, height, borderWidth) {
  this.x=x;
  this.y=y;
  this.width = width;
  this.height = height;
  this.borderWidth = borderWidth;
}

function DrawRects(){
  myRectangle = new Rectangle (250,70,100,50, 5);

  context.rect(myRectangle.x,myRectangle.y,myRectangle.width,myRectangle.height)
  context.fillStyle="#8ED6FF";
  context.fill();
  context.lineWidth=myRectangle.borderWidth;
  context.strokeStyle="black"; 
  context.stroke();
}

function updateStageObjects() {
  var amplitude = 150;
  var centerX = 240;    
  var nextX = myRectangle.x+ 10;

  myRectangle.x = nextX;    
}   

function clearCanvas() {
  context.clearRect(0,0,canvas.width, canvas.height);
}

function DrawRect(){
  alert("Test1");
  setTimeout(CheckCanvas,10);

  //clearCanvas();

  updateStageObjects();

  DrawRects();
  alert("Test2");
}

function CheckCanvas(){
  return !!(document.createElement('canvas').getContext);
}   

function CheckSound(){  
  return !!(document.createElement('sound').canPlayType)
}

function CheckVideo(){
  return !!(document.createElement('video').canPlayType)
}

function Checkstorage(){
  return !!(window.localStorage)
}

function CheckVideo(){
  return !!(document.createElement('video').canPlayType)
}

function DrawCanvas(){
  if (CheckCanvas()){
    canvas = document.getElementById('Canvas');
    context =canvas.getContext('2d');

    $('#Result').text('Canvas supported...');
    $('#Result').text($('#Result').text()+'Sound supported...'+CheckSound());
    $('#Result').text($('#Result').text()+'Video supported...'+CheckVideo());   
    $('#Result').text($('#Result').text()+'Storage supported...'+Checkstorage());

    DrawRects();
    setInterval(DrawRect(), 10);
  }
}
</script>

Html:

<canvas id="Canvas" width="800px" height="800px" onclick="DrawCanvas()"> Nor supported</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-23T08:54:32+00:00Added an answer on May 23, 2026 at 8:54 am

    You need to do

    setInterval(DrawRect, 10);
    

    Using DrawRect() will invoke the function once, and then try to call the result of that function, as a function (which it isn’t) every 10 milliseconds.

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

Sidebar

Related Questions

I wanted to do a sort of animation where a rectangle would move..However, the
I wanted to generate one fix view using interface builder, but the size of
I wanted to do something like this: <asp:Label ID=lblMyLabel onclick=lblMyLabel_Click runat=server>My Label</asp:Label> I know
I just wanted to know why Excel-2007 record macro does not write anything for
I posted a question similar to this earlier, however, after thinking about it and
Basically, I wanted to add a few custom methods to google.maps.Map and Rectangle classes.
This may be a more math focused question, but wanted to ask here because
Wanted to create a fun app with photo. This is the scenario: I have
Just out of curiosity, I wanted to do this and created some shapes like
wanted a solution on how to access the javascript variable inside the java scope.

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.