javascript - Get canvas size from its context -
i'm building few libraries canvas graphing in javascript, , wondering if there way size of canvas it's 2d context. looking this.
var size=ctx.size; scale=size/100;
there multiple canvas elements here, can't canvas.width.
thanks
yes can. it's bit deeper might used to;
var sizewidth = ctx.canvas.clientwidth; var sizeheight = ctx.canvas.clientheight; var scalewidth = sizewidth/100; var scaleheight = sizeheight/100;
a common example of canvas context object;
> canvasrenderingcontext2d canvas: htmlcanvaselement constructor: canvasrenderingcontext2dconstructor fillstyle: "#000000" font: "10px sans-serif" globalalpha: 1 globalcompositeoperation: "source-over" linecap: "butt" linejoin: "miter" linewidth: 1 miterlimit: 10 shadowblur: 0 shadowcolor: "rgba(0, 0, 0, 0)" shadowoffsetx: 0 shadowoffsety: 0 strokestyle: "#000000" textalign: "start" textbaseline: "alphabetic" webkitbackingstorepixelratio: 1 webkitlinedash: array[0] webkitlinedashoffset: 0 __proto__: canvasrenderingcontext2dprototype
and htmlcanvaselement inside it;
> canvas: htmlcanvaselement accesskey: "" attributes: namednodemap baseuri: "http://fiddle.jshell.net/_display/" childelementcount: 0 childnodes: nodelist[0] children: htmlcollection[0] classlist: domtokenlist classname: "" clientheight: 150 clientleft: 1 clienttop: 1 clientwidth: 300 constructor: htmlcanvaselementconstructor contenteditable: "inherit" dataset: domstringmap dir: "" draggable: false firstchild: null firstelementchild: null height: 150 hidden: false id: "c1" innerhtml: "" innertext: "" iscontenteditable: false lang: "" lastchild: null lastelementchild: null localname: "canvas" namespaceuri: "http://www.w3.org/1999/xhtml" nextelementsibling: htmlcanvaselement nextsibling: text nodename: "canvas" nodetype: 1 nodevalue: null offsetheight: 152 offsetleft: 8 offsetparent: htmlbodyelement offsettop: 8 offsetwidth: 302 onabort: null onbeforecopy: null onbeforecut: null onbeforepaste: null onblur: null onchange: null onclick: null oncontextmenu: null oncopy: null oncut: null ondblclick: null ondrag: null ondragend: null ondragenter: null ondragleave: null ondragover: null ondragstart: null ondrop: null onerror: null onfocus: null oninput: null oninvalid: null onkeydown: null onkeypress: null onkeyup: null onload: null onmousedown: null onmousemove: null onmouseout: null onmouseover: null onmouseup: null onmousewheel: null onpaste: null onreset: null onscroll: null onsearch: null onselect: null onselectstart: null onsubmit: null onwebkitfullscreenchange: null onwebkitfullscreenerror: null outerhtml: "<canvas id="c1"></canvas>" outertext: "" ownerdocument: htmldocument parentelement: htmlbodyelement parentnode: htmlbodyelement prefix: null previouselementsibling: null previoussibling: text scrollheight: 150 scrollleft: 0 scrolltop: 0 scrollwidth: 300 spellcheck: true style: cssstyledeclaration tabindex: -1 tagname: "canvas" textcontent: "" title: "" translate: true webkitregionoverflow: "undefined" webkitdropzone: "" width: 300 __proto__: htmlcanvaselementprototype
Comments
Post a Comment