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
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Determining the screen size with JavaScript7m 41s
-
(Locked)
Detecting a change in screen size4m 1s
-
(Locked)
Loading alternative content based on screen size3m 11s
-
Setting up the mobile nav button4m 6s
-
(Locked)
Setting up the mobile nav panel4m 7s
-
Opening and closing the nav panel7m 20s
-
(Locked)
-
-
-