html5 - Javascript setInterval works but not infinite loop -
html5 - Javascript setInterval works but not infinite loop -
i don't understand why infinite loop not work uncommenting function phone call works.
<body> <canvas id="mycanvas"style="border:2px solid black;" width="1600" height="900"> browser not back upwards html5 canvas tag. </canvas> <script> var c = document.getelementbyid ("mycanvas").getcontext ("2d"); var boxsize = 25; var numboxes = 1; var x = 1000; var dx = 1; var y = 100; var dy = 1; var = 0.01; var da = 0.1; var size = 20; var w = c.canvas.width; var h = c.canvas.height; //function testing () { while (true) { c.clearrect (0, 0, w, h); x = x + 1; y = y + 1; = + 0.1; x = x + dx; y = y + dy; if (x < size / 2 || x + (size / 2) > w) { dx = -dx; da = -da; } if (y < size / 2 || y + (size / 2) > h) { dy = -dy; da = -da; } c.save (); c.translate (x, y); c.rotate (a); c.strokerect (-size / 2, -size / 2, size, size); c.restore (); } // testing (); // setinterval (testing, 10); </script> </body>
when utilize setinterval
maintain adding function calling queue of things browser do. repaint events added queue.
when utilize infinite loop, browser never gets end of function, never gets around running repaint , image in document never updates.
javascript html5 dom setinterval
Comments
Post a Comment