Skip to main content
Participant
September 7, 2015
Answered

Centre html in browser (html canvas). please help.

  • September 7, 2015
  • 2 replies
  • 1494 views

Hi Guys.

I'm really stuck here, and hope someone can help. I have looked over the internet and found some answers but Im not good enough with code to be able to figure out how to to edit this to centre it in the browser window. This code - published from flash cc with html canvas - looks different to other peoples code. Could someone please point to where I need to add the 'align: centre' or 100% or whatever is needed. thank you all!

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>change curve animation flash</title>

<script src="http://code.createjs.com/easeljs-0.8.1.min.js"></script>

<script src="http://code.createjs.com/tweenjs-0.6.1.min.js"></script>

<script src="http://code.createjs.com/movieclip-0.8.1.min.js"></script>

<script src="http://code.createjs.com/preloadjs-0.6.1.min.js"></script>

<script src="change curve animation flash.js"></script>

<script>

var canvas, stage, exportRoot;

function init() {

  canvas = document.getElementById("canvas");

  images = images||{};

  var loader = new createjs.LoadQueue(false);

  loader.addEventListener("fileload", handleFileLoad);

  loader.addEventListener("complete", handleComplete);

  loader.loadManifest(lib.properties.manifest);

}

function handleFileLoad(evt) {

  if (evt.item.type == "image") { images[evt.item.id] = evt.result; }

}

function handleComplete(evt) {

  exportRoot = new lib.changecurveanimationflash();

  stage = new createjs.Stage(canvas);

  stage.addChild(exportRoot);

  stage.update();

  stage.enableMouseOver();

  createjs.Ticker.setFPS(lib.properties.fps);

  createjs.Ticker.addEventListener("tick", stage);

}

</script>

</head>

<body onload="init();" style="background-color:#D4D4D4">

  <canvas id="canvas" width="1024" height="768" style="background-color:#FFFFFF"></canvas>

</body>

</html>

This topic has been closed for replies.
Correct answer Nancy OShea

Change this

    <canvas id="canvas" width="1024" height="768" style="background-color:#FFFFFF"></canvas>

to this:

    <canvas id="canvas"></canvas>

Add the following CSS code to your <head> tag.  You can put it under your <script>

<style>

    #canvas {

          background: #FFF;

          width: 1024px;

          height: 768px;

          margin: 0 auto; /**this is horizontally centered**/

    }

</style>

Nancy O.

2 replies

Rob Hecker2
Legend
September 7, 2015

change curve animation flash.js

Don't put spaces or special characters in file names, and use lower case only.

Nancy OShea
Community Expert
Community Expert
September 7, 2015

That's very good advice.

Spaces get converted to %20 entities which can lead to failed link paths in some browsers.  Also spaces are not valid in HTML5 documents.

To avoid problems, I try to stick to a standard naming convention I can repeat.  For example, all lowercase file & folders names with hyphens- or underscores_ between words when needed.

Nancy O.

Nancy O'Shea— Product User & Community Expert
Nancy OShea
Community Expert
Nancy OSheaCommunity ExpertCorrect answer
Community Expert
September 7, 2015

Change this

    <canvas id="canvas" width="1024" height="768" style="background-color:#FFFFFF"></canvas>

to this:

    <canvas id="canvas"></canvas>

Add the following CSS code to your <head> tag.  You can put it under your <script>

<style>

    #canvas {

          background: #FFF;

          width: 1024px;

          height: 768px;

          margin: 0 auto; /**this is horizontally centered**/

    }

</style>

Nancy O.

Nancy O'Shea— Product User & Community Expert