get-2d-context

1.0.1 • Public • Published

usage

var container = document.querySelector('#myContainer')
 
var options = {
    responsive: true,
    fullscreen: false
}
 
// a canvas will be appended to container
// if container is left unspecified the default container is document.body
// the width and height of canvas is equal to container
var ctx = get2dContext(container, options)
 
if(!ctx) {
    // canvas is not supported on this device
} else {
    // magic!!1
}

options

  • ##### responsive

    • is true by default
    • keeps canvas.width and .height equal to container
  • ##### fullscreen

    • is false by default
    • use only when container === document.body
    • sets document.body.width = window.innerWidth && .height = window.innerHeigght
    • applies css styles to document.body (overflow: 'hidden', margin: 0, padding: 0)

Package Sidebar

Install

npm i get-2d-context

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • olivierrr