From the course: Creating a Responsive Web Experience

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Determining the screen size with JavaScript

Determining the screen size with JavaScript

From the course: Creating a Responsive Web Experience

Determining the screen size with JavaScript

Now to begin detecting the size of our window with JavaScript, let's switch back to our Text editor. Let's open up design.js and we're going to need to define a few variables at the top of the document here. So let's add a few returns before the document ready. Let's start by typing var then a space. The variable name's going to be windowSize. We're going to set this equal to two tick marks, and a semicolon. So it's going to be a string literal, and we're going to set this to nothing or null. Next variable, we're going to call this windowWidth. We're going to set this equal to 0. Then hit a Return. Then we're going to set another variable called actualSize. We're going to set this equal to 0 as well. So now with our variables created, let's come down under the document ready. Let's create another custom function. We're going to say, function, space and we are going to call this, checkBrowserSize. Put in our parenthesis, then our brackets, split that open on the brackets. And we're…

Contents