English 中文(简体)
我如何使这一悲观工作发挥作用?
原标题:How do I make this animation work?

我想要的是横向行动。 然而,这并不是一帆风顺。 我如何确定这一点?

<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>
最佳回答

你们需要做事

setInterval(DrawRect, 10);

使用<代码>DrawRect(),将一度援引该功能,然后试图将该功能的result称作每10毫米秒(即t)。

问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签