javascript - fillRect causes entire screen to change color -
i have webpage iframe in it, , within iframe there canvas id="canvas", when call (from .js file within iframe) fillrect on context of canvas entire web page (both inside , outside iframe turns grey. how prevent happening?
this javascript:
var canvas = document.getelementbyid('canvas') var ctx = canvas.getcontext('2d'); ctx.fillrect(0, 0, 100, 100); this html within iframe:
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <link rel="stylesheet" href="main.css"> </head> <body class="canvas"> <canvas id="canvas" width="600" height="400"></canvas> <script src="game.js"></script> </body> </html> this css styling (which both iframe , webpage iframe use):
* { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; margin: 0; overflow: scroll; padding: 0; } body { background-color: #999999; /*this color entire screen turning*/ } canvas { height: 400px; overflow: hidden; width: 600px; } canvas>canvas { height: 100%; width: 100%; } i find annoying iframe can affect webpage in, main reason used iframe isolate , javascript related isolated rest of web page , seems not well. how fix bug , there way can isolate iframe not affect rest of webpage regardless of javascript put or @ least affects little possible.
edit: should mention if remove ctx.fillrect() works intended , web page doesn't turn grey.
edit2: should mention when turn grey, mean in foreground turned grey , covered on every other element on page (i have tags , various other things in main web page contains iframe, non-grey thing on screen in 100*100px black box, every piece of text / title / button etc. covered grey.
edit3: https://s3-us-west-2.amazonaws.com/dannys-aws/public/high+score+master+1.zip page in question if test yourself.
the issue overflow: auto; adding scroll bars every element.
Comments
Post a Comment