Note that there are some explanatory texts on larger screens.

plurals
  1. POCentering canvas-element in Google Chrome using KineticJS
    primarykey
    data
    text
    <p>In the following code sample I am using an image that is drawn onto the HTML5-canvas element. However, when testing this in Chrome it does not immediately center the image. IE doesn't have a problem with this (using IE9). When you select one of the elements in the DOM using the developer window in Chrome, somehow it THEN suddenly centers!!! Its hard to debug since you can't see what's changing what:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta content="text/html; charset=utf-8" http-equiv="Content-Type" /&gt; &lt;title&gt;Untitled 2&lt;/title&gt; &lt;script type="text/javascript" src="http://www.html5canvastutorials.com/libraries/kinetic-v3.10.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; window.onload = function () { var stage = new Kinetic.Stage({ container: "container", width: 578, height: 200 }); var layer = new Kinetic.Layer(); var imageObj = new Image(); imageObj.onload = function () { var image = new Kinetic.Image({ x: stage.getWidth() / 2 - 53, y: stage.getHeight() / 2 - 59, image: imageObj, width: 106, height: 118 }); // add the shape to the layer layer.add(image); // add the layer to the stage stage.add(layer); stage.draw(); }; imageObj.src = "http://www.html5canvastutorials.com/demos/assets/yoda.jpg"; }; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Page 3&lt;/h1&gt; &lt;div style="text-align: center"&gt; &lt;div id="container"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload