Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
¿Cómo mover el lienzo hacia atrás en javascript?

Trato de pensar cómo el cuadro puede moverse hacia atrás cuando llega a 1000px (canvas.width), pero no sé cómo se resuelve después de la condición If, así que ahí está mi script, ¿alguien puede ayudarme?

 var canvas = document.querySelector("canvas"); var canvasCT = canvas.getContext("2d"); var x = 50; function draw() { canvas.width = canvas.width; canvasCT.fillStyle = "blue"; canvasCT.fillRect(x, 50, 100, 100); } function run() { draw(); x += 5 ; if (x > 1000) { ...... } } setInterval(run, 10);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 var canvas = document.querySelector("canvas"); var canvasCT = canvas.getContext("2d"); var x = 50; var speed = 5; function draw() { canvas.width = canvas.width; canvasCT.fillStyle = "blue"; canvasCT.fillRect(x, 50, 100, 100); } function run() { draw(); x += speed; if (x > 1000 || x < 0) { speed = -speed; } } setInterval(run, 10);
 <canvas width=1000></canvas>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!