0

I am attempting to code the game breakout in javascript. Currently I have it working using JQuery in several locations. My professor does not want the class to use Jquery so I have to change the areas I use jquery to javascript.

function windowsize() {
WIDTH = $("#canvas")[0].width = ($(window).width()-20.5);
HEIGHT = $("#canvas")[0].height = ($(window).height()-20.5);

}

windowsize();

I am using this function to get reference to the canvas element and subtracting from the sides to remove the scrollbar. (on a side note if anyone knows how to remove the scroll bar without subtracting let me know!)

I attemped the following code to get reference to the canvas, but cannot get it to work?

var c=document.getElementById("canvas"); 
var ctx=c.getContext("2d");

Here is my fiddle: http://jsfiddle.net/Kinetic915/kURvf/29/

Any help is appreciated!

Thanks!

user2138152
  • 131
  • 3
  • 10

1 Answers1

0

Assuming Chrome, document.documentElement.clientWidth seems to do it for you. Or, find a 100% width element on the page and get the width of that.

imjared
  • 19,492
  • 4
  • 49
  • 72