Create a Sliding Tabbed Panel with jQuery and Dreamweaver

Create a Sliding Tabbed Panel with jQuery and Dreamweaver

with Chris Converse

 


A tabbed panel interface is a classic feature to incorporate in your website design, but they're usually static elements. This course shows how to build a dynamic sliding tabbed panel from scratch using a combination of HTML, CSS, jQuery, and the tools in Dreamweaver. Author Chris Converse leads you through the process from start to finish, from building the containers to styling the text, tab, and panels, and adding click events to make the tabs interactive. He also shows how to incorporate progressive enhancement techniques, so visitors who don't have JavaScript, for example, can still access the content.
Topics include:
  • Creating the main panel and tab containers
  • Adding content to the containers
  • Adding CSS styles to the text and tabs
  • Adding the jQuery $(document).ready() function
  • Assigning click events to the tabs
  • Setting an autostart on page load
  • Creating custom graphics for the panels
  • Assigning custom classes to the HTML elements
  • Reassigning CSS rules with JavaScript

show more

author
Chris Converse
subject
Developer, Web, Web Design, Projects, Web Development
software
Dreamweaver CS5, CS5.5, CS6, jQuery
level
Intermediate
duration
1h 6m
released
Oct 11, 2012

Share this course

Ready to join? subscribe


Keep up with news, tips, and latest courses.

submit Course details submit clicked more info

Please wait...

Search the closed captioning text for this course by entering the keyword you’d like to search, or browse the closed captioning text by selecting the chapter name below and choosing the video title you’d like to review.



Introduction
Previewing the final project
00:04Hi! I am Chris Converse, and in this course we're going to be building a sliding tabbed panel
00:07for your website.
00:08I want to start by showing the final project.
00:11We're going to be creating this tab panel here where when I click on individual tabs,
00:15the content inside is going to swipe back and forth to animate to the content that corresponds to the tab.
00:21We're also going to set it up so that you can start on a particular tab.
00:26So if I come up here and hit Reload, we're going to actually start this on the second
00:28tab, and we'll show you how to set this to anyone of the tabs.
00:31We are also going to build a styled version of this as well.
00:35So if you just like to stop at this point in the course with a generic style to apply
00:39your own design to, you can, or you can come in here and we can create more customized designs.
00:46So, in this case, we have custom background graphics and custom type styles and layouts
00:51inside of each individual tab panel.
00:55Now there is one more aspect we're going to be building into this course:
00:57we're going to be taking a look at applying progressive enhancement techniques.
01:01So if somebody were to visit this tab panel without having JavaScript enabled, this is
01:05what the user would see.
01:07They would see all of the content from the panels stacked up.
01:10They would still see the CSS in place, but, again they wouldn't have that sort of tabbed
01:13panel or enhanced user experience.
01:16Then of course if somebody didn't have JavaScript or CSS, they would see a nicely laid out page like this.
01:21At the end of the course we're going to talk about some of those progressive enhancement
01:25techniques and how we can apply some of those earlier courses I have in the lynda.com online
01:29training library.
01:31So I hope this course sounds interesting to you, and if so let's get started.
Collapse this transcript
About the exercise files
00:00When you download the exercise files there is going to be a series of folders inside of there.
00:04Now if you're a Premium subscriber to the lynda.com online training library, you'll
00:08have the access to all five of these folders.
00:10If you're not a Premium subscriber, you'll have the access to folders 1 and 2.
00:14These are the minimum number of files that you'll need to be able to complete the course.
00:19Now, inside of folder 1, we have Files to add.
00:21We're going to copy these into our main project folder to give us a jumpstart.
00:25This includes an HTML file, and then in the includes directory, two CSS files and a JavaScript file.
00:31These are empty but are hooked into the index.html file.
00:34Then finally, there's an images folder.
00:36So in case you want to skip the Photoshop part where we customize these graphics, you
00:40can just skip that chapter and move on.
00:43Now inside of folder 2, we have two snippet files.
00:46These files have some placeholder text and some CSS rules that we can cut and paste later in the course.
00:52Inside of folder 3 is a source Photoshop file.
00:54You can use this file to create custom background graphics.
00:58Inside folder 4 is a copy of the generic version of the project.
01:02As we go through this course, we're going to be creating a sliding tab panel which is going
01:05to have very little styling in it but will be fully functional.
01:08If you want to stop the project there and use that as the project to implement into
01:12your website, you can use this one.
01:15Then inside of folder 5 is the fully styled one that has backgrounds and different graphic
01:19colors and so forth.
01:21So now that we're familiar with the exercise files, we can start building our project in the next movie.
Collapse this transcript
Beginning the project
00:00Now, to begin our project let's create a folder on the desktop.
00:06We'll call this mySlidingPanels.
00:08I'm just going to open this up and resize this a little bit.
00:14Now, with our project folder created, let's come back to the Exercise Files.
00:17Let's open up folder 1, called Files to add.
00:20Let's select the images directory, the includes directory, and the index.html file, and let's
00:25drag a copy of these into the project folder we created on the desktop.
00:29So once all of these are in place, we'll come back to the exercise file.
00:34Let's close up folder 1.
00:36Now that we've all of our startup files in place, we can start editing the HTML.
Collapse this transcript
1. Creating the HTML Containers
Creating the main panel and the tab containers
00:00Now, to begin editing our HTML file, let's open up index.html up in Adobe Dreamweaver.
00:06Now, if you prefer to take this course in a more code-oriented tool, we're offering the
00:10same course in the lynda.com library using a text editor instead of Adobe Dreamweaver.
00:15Now inside of Dreamweaver, let's come over to the Code view of this particular document,
00:19and I want to point out some things that I've added into this file already.
00:23First is we have a link to the sliding_panels.css file.
00:26We also have a link into jQuery, a link into a sliding_panels.js file, and then down here
00:32we have links into a Google html5shiv,
00:36if the version of IE is less than 9. So here we're linking to the Google shiv.
00:41This is going to ensure the fact that were using a document type here, which is for HTML5,
00:46that IE7 and 8 will be able to understand this.
00:48And we also have a link to a special IE CSS file so that we can redefine some of the CSS
00:543 properties that IE 7 and 8 don't support.
00:57And if you're using a more recent version of Dreamweaver, you'll see the related files
01:00up here actually match these items that we were just looking at.
01:04So the first thing we're going to do is create some content containers.
01:07So we're going to do this inside of Code view to make sure that the structure of the HTML
01:11is exactly what we need.
01:12So I have a comment in here called Sliding Panels go here.
01:16You can take that comment and then delete it, and we're going to put in our main HTML
01:20content containers for the sliding panels.
01:23The first one is going to be a div tag. So I'll start a new tag, div.
01:28We'll set a class of SP on this item.
01:32Let's end the tag and let's end the element.
01:36This is going to be the main container for our sliding panels.
01:40Inside of here we're going to add another div.
01:41We're going to set a class of tabs on this.
01:47End that tag and end that element.
01:51Let's put that on the next line, and let's add another div inside of the container div.
01:58This one is going to have a class of panel_container, and then end that element.
02:10Now, with our main HTML containers complete, we'll add some additional containers for our tabs.
Collapse this transcript
Creating the HTML containers for the tabs
00:00So now we'll add HTML containers for the individual tabs.
00:04So let's get our cursor inside of the div with the class of tabs.
00:08Let's tab in, and we can put HTML elements inside of here that we'll use as our individual
00:12tabs that our users can click on.
00:13Now you can use any HTML element here that you want.
00:16Sometimes people like to put unordered lists inside of here or use straight anchor tags.
00:21Instead, I'm going to choose to use a span tag.
00:24We'll type "iPad," then we'll end this span element.
00:27Let's hit a teturn.
00:30Write another span. This one is going to be for Video and the element.
00:36Let's add one more. This one will be Photography, and end that element.
00:45Now that we have the HTML elements that we're going to use as tabs, in the next movie we
00:48can start working on the panels inside of the panel container div.
Collapse this transcript
Creating the HTML containers for the panels
00:00Now, for the panel containers, let's come up here and split the div open a little bit that's
00:06got the class of panel container.
00:09Let's tab in, and let's add another div inside of here.
00:11We're going to give this a class of panels, plural.
00:17We're going to end that element.
00:20Let's split that open. And inside of here we're going to put each individual panel.
00:26We'll start with another div inside of the class of panels.
00:30We're going to give this a class of panel, singular.
00:36Let's end that div tag.
00:38Let's open up one individual panel, and then inside of here we're going to put one more div.
00:43We're going to give this a class of panel_content and end that div.
00:54So now this constitutes one panel.
00:57Let's copy this to the clipboard, let's hit a return, and let's paste it two more times.
01:05So now inside of our panel container we have one div called panels and then inside of there
01:10we have three individual divs, each one classed with panel, and then inside of each one of
01:15those we have a div with panel content.
01:18So now we have all of the HTML containers that we need inside of panel container for
01:22all of the individual panels.
01:24Next, we can start adding in some of the content for the individual panels.
Collapse this transcript
Adding content to the containers
00:00Now, to add content for these panels, we're going to come over to our snippets.
00:04So in Dreamweaver come up to the File menu, choose Open.
00:08Locate your Exercise Files. Go into folder 2 called Snippets and open up A-panel-content.html, then click Open.
00:17So inside of here I have just some content about some of my other lynda.com courses that
00:20we can cut and paste into the individual panels.
00:23So the very first panel, which is for the iPad, let's come over here and copy the h2 all the
00:28way up through the ending paragraph tag.
00:30Let's copy that to the clipboard.
00:33Let's come back to index.html and inside of panel_content for the first panel, let's tab
00:38in and let's paste all of that content.
00:41I'm going to format this a little bit as well; I'll just select these lines, hit the Tab
00:46key, and just tab these in so that these three elements here all line up.
00:51Let's come back to our panel_content.
00:54Let's scroll down to the content for the video Panel.
00:58Select from the h2 all the way up through the ending paragraph tag, copy that. index.html.
01:03Let's come back and find the second panel.
01:08Let's tab in and paste all of that content. Again, I'm going to format this as well, to
01:14line up all of the element tags.
01:16Let's scroll down. This is our third panel.
01:18Let's come back to our snippets.
01:20Let's scroll down and find all of the content for the photography panel.
01:26Select all of this, copy to the clipboard. Back to index.html.
01:32Inside of panel_content for the third panel, let's paste all of that content.
01:42So with all of our content in place, let's switch back to Design view.
01:45Now, inside of Design view, we'll see all of the content that we just added.
01:48We can see our tabs up here inside of a div, and Dreamweaver shows us the divs with a dotted
01:52line, and then we can see our three individual panels here as well.
01:57So, now with all of our content containers in place and all the content inside of those
02:01containers, we're ready to start doing some CSS.
Collapse this transcript
2. Styling the Tabs and Panels
Adding CSS styles to the text
00:00Now we want to create some CSS rules to style the text inside of the panels.
00:04Now, we're going to be using compound rules, which means we want to target only the text
00:08that's inside these panels. And Dreamweaver gives us a nice little shortcut to help us
00:11write a compound rule.
00:13So if have my cursor inside of one of the panels--and I can see on the document tree here
00:18that I'm inside of the paragraph tag, inside of panel_content--and we can see this follows
00:22all way up to to the div.sp, which is the overall container for our sliding panel.
00:27With my cursor inside of here, I come over to this CSS styles property, click on Create
00:32New Style, and when we select Compound from the type of list, notice that Dreamweaver will
00:37write a compound rule targeting exactly the element I had selected, all the way from the
00:42highest-most parent, which in this case is the sp tag.
00:47Now we don't need this to be quite as specific, so let's come in here and let's remove all
00:50of the intermediate rules.
00:53And we're just going to have .sp--the outermost container--space p.
00:57So we want to target the paragraph tags inside of the outermost container for our sliding panel.
01:02Next, let's come down here and make sure that we have the sliding_panels.css chosen so
01:07that when we write CSS rules here, even though we're in the index.html file, those rules will
01:12go into the sliding_panels.css file.
01:16Let's click OK. Now for paragraph we're going to come in here to Font-size.
01:20We're going to specify 1 em. And over at the Box properties, let's come in here, and let's
01:26uncheck Margin Same for all, and let's add a 0 on the Top, 0 on the Right, we're
01:32going to add 1 em on the Bottom, and then 0 on the Left.
01:37Now, when I click Apply we can see some slight changes over in the left-hand side here.
01:42We can see that we now have these individual paragraphs have no margin at the top.
01:47Let's click OK. Let's create one more rule.
01:49We want this to be for an h2.
01:51So I'll select a couple of characters in the heading. Come over here, create a new CSS rule, Compound.
02:00Let's get rid of all of the intermediate classes, so we have .sp h2. Click OK.
02:07What we're going do here for Font-size, we are going to type 1.15 ems; this will give
02:12us a 15% increase on the base font size.
02:16Box properties, uncheck Same for all from Margin.
02:19We're going to type 0 on the Top, 0 on the Right, .5 ems on the Bottom. and 0
02:27on the left, and then click Apply.
02:30Once we do that, you'll see all of the h2 tags now stick right to the very top of the panel
02:34because we've removed the top margin.
02:36And since the paragraph tags have the top margin removed as well, we're getting exactly
02:40half an em between the h2 and the paragraph tag.
02:43So let's come over here and click OK.
02:47Now that we have the CSS rules in place to style the text in the panels, next we'll work
02:51on some CSS rules that will target the layout of the panels.
Collapse this transcript
Adding CSS styles to the tabs
00:00Now that we have some CSS rules in place to style the text, let's create some CSS rules for the layout.
00:05Let's come over to the CSS Styles panel.
00:08Let's create a new rule.
00:09This is going to be a class, .sp.
00:13We're going to target the main sliding panel container. Click OK.
00:18Let's come over to the Box properties. First we're going to set a Width, 325 px.
00:23Let's come over here to the Float.
00:26We're going to set this to right.
00:30Let's come down to Margin, uncheck Same for all.
00:32We're going to set 0 on the Top, 0 on the Right, 10 pixels on the Bottom, and 25
00:37pixels on the Left.
00:40Next let's come over to Positioning and let's set the Positioning to relative.
00:45What that's going to do is make sure that any elements inside of the sp container are
00:49going to be positioned relative to the container itself.
00:51Now let's come down here and click Apply. And if I move this window out of the way, we can
00:57see that the sp container has now been conformed to 325 px, is floating over to the right, and
01:02allowing content to go on the left-hand side.
01:06So with that in place, let's click OK. Now let's create another rule.
01:09We're going to target the tabs container, so this is going to be a compound rule, .sp .tabs.
01:18Let's click OK. What we are going to do inside of here. Let's come down to Positioning.
01:21We're going to set Positioning inside of here to relative as well.
01:25And then we're going to come down to the Z- Index and we're going to set this to 101.
01:31Now we're setting this because the natural Z-Index would be in the order of the HTML
01:34code, and since the tabs come before the panel container, the tabs would be behind the panel container.
01:40But assigning an absolute Z-Index for this object and assigning a lower number for the
01:44panel container will make sure that the tabs will be in front of the panel container.
01:48That way when we select the tabs, they'll actually look like they are connecting to the content.
01:53With those settings let's come down and click OK.
01:55And let's create one more.
01:56We want to target the spans now inside of the tabs container.
01:59So let's create another rule, compound, .tabs span. Let's click OK.
02:12This targets the actual elements that we want to have look and behave like a tab.
02:17So what we're going to do inside of here is let's come down to the Box properties.
02:21For Margin we're going to set 0 and leave that same for all.
02:24For Padding, let's uncheck Same for all. Let's add 8 px on the Top, 12 px on the Right, 8
02:32px on the Bottom, and 12 pixels on the Left.
02:36Next let's come over to the Block properties.
02:39For Display, let's type inline-block.
02:45Next, let's come over to Positioning.
02:47We're going to set Positioning to relative.
02:50Next, let's go to Background.
02:52Let's set the Background- color to white, which is #FFF.
02:56And then lastly, let's come down to the Border settings, and let's come over here and uncheck
03:02Same for all for the Style, Width, and Color.
03:06And so for Top, let's come down here and choose solid 1 px and #CCC for a medium gray.
03:14And let's set the same properties for the Bottom, so solid 1 px and #CCC for medium gray.
03:23Now, we are not going to set the right and left borders in this particular rule.
03:26We're going to do that in another rule, to target either the first or the last tab so
03:30that we don't get the borders doubling on the right and left sides.
03:33So at this point let's click OK.
03:36So now in the background you see the tabs are white and since we set a relative property
03:40and give it a Z-Index, it's actually showing up on top of the panel container.
03:43So now that we have the CSS rules in place to target the top and bottom borders of the
03:47tabs, next we'll work on creating rules that will target the first tab and the last tab
03:52and set the right and left borders on those.
Collapse this transcript
Styling the first and last tabs
00:00So at this point we need to add two CSS rules in that Dreamweaver doesn't have support for
00:03in its visual interface, but we can add them into the code.
00:07So let's open up the CSS file, go up to the File menu, choose Open.
00:12Inside of mySlidingPanels go to includes, open sliding_panels.css.
00:19Once in here, let's scroll down to the bottom.
00:21I am going to add a few lines down here.
00:25And what we want to do is target the first child span, so let's start by typing the .sp,
00:31space, .tabs, space, span, colon. That specifies the pseudo-class first-child.
00:42Let's put in our brackets.
00:51So for the very first child, or the first tab, what we're going to want to do is set a padding-left,
00:56set that to 15 pixels.
01:02This will give us little bit more room on the left-hand side of the text for the rounded
01:05corner that we're going to put into the top left.
01:07Let's hit a return.
01:09Next, we're going to do border-left, colon, space, and we're going to use shorthand style here,
01:161 pixel for the size. Next is the style solid Space, then the color pound, and three 's
01:25for medium gray.
01:27I'm going to select this property.
01:29Let's copy that to the clipboard, paste it on the next line, and change border-left to border-right.
01:34Let's scroll down here again.
01:38Next, we're going to specify some CSS3 properties for the rounded corners, and we still need
01:42to use some of the rendering engine flags to make sure that this works in browsers like
01:46Firefox and Chrome and Safari.
01:50So first, we'll type -webkit-border. And if you have a later version of Dreamweaver, CS5
01:59or later, Dreamweaver will actually help you with some CSS3 properties. So we want to come
02:04over here and choose border-top-left- radius, then a space, then 12 pixels.
02:12Next line we're going to target Mozilla, so -moz-border -radius-topleft as one word, colon, space, 12 pixels.
02:27Now the syntax between Mozilla and WebKit are little different.
02:32On the next line, we're going to put the name of the final CSS property, so once the CSS3
02:36specification is finalized, all the browser will support this tag. Type border-top-left-radius 12 pixels.
02:47So now with the first tab defined, let's come up here, copy this entire rule.
02:54Let's paste it after, and let's change some of the properties here.
03:00So instead of first child, we're going to target last child. Instead of padding-left, we're
03:06going to change that to padding-right.
03:07And instead of border-top-left-radius, we're going to change that to border-top-right, and
03:17the Mozilla, change left to right, and for the final property, we'll change this from left
03:22to right as well.
03:25Now, since we're in the Code view let's just add one more final rule.
03:28This is going to be for the selected state of the tabs.
03:32So I'll type .sp .tabs span.selected. This is the class that we're going to dynamically
03:42assign onto the individual spans depending on which item the user clicks on. We'll do
03:48that with JavaScript later.
03:52Now inside here, what we're going to do is set the color so pound sign and three 9s for a medium gray.
04:00Now in the next line we're going to set border bottom, so border-bottom: 1px solid,
04:11and then we're going to set white.
04:14This is going to give us the illusion that the bottom border being white is going to
04:17look like the tab connecting to the content.
04:20Let's save our file.
04:23Next, we need to add a CSS rule for IE 7 and 8, since they don't support the CSS3 properties
04:28we just added in.
04:29So let's come to the File menu.
04:31Let's choose Open.
04:33Let's open sliding_panels_ie.css.
04:37Now, in here we just simply want to set a border for all four sides.
04:40So .sp .tabs span, beginning and ending bracket. And inside of the brackets
04:50let's just type border, and if we just the word border that will target all four sides.
04:561 pixel, solid, and then three Cs for gray and hit Save.
05:05Now to test this let's come back to our index.html file.
05:09Let's choose Files > Save All.
05:12Now, if you're using a later version of Dreamweaver, you'll have a Live View button here.
05:15If you don't have a Live View button, you can go to the File menu, come down to Preview
05:19in Browser, and you can pick any browser on your system.
05:21I am going to come in here and click Live View inside of Dreamweaver's panel, and I can
05:26see that these individual panels now show up with the rules we just created.
05:30The first child here, the first span, has around a corner on the top left. The last one has
05:34around a corner on the top right.
05:36I have a little bit of extra padding over here on the side of photography and a little bit
05:40of extra padding on the left side of iPad.
05:43Now you notice that these are spaced out a little bit.
05:45One of the thing that's happening here is the hard returns in our code are being rendered
05:49as spaces in the browser.
05:52So let's come out of Live View.
05:54Let's come back into Dreamweaver's HTML file. Let's go into Code view. Let's scroll up in
05:59Code view, and let's find the div with the tabs class, right here.
06:04And what we're going to here is just remove all the whitespace in here.
06:08So we have each of the spans starting and stopping without any spaces in between. There we go.
06:17Let's switch back to Design view.
06:19Let's click back into Live view and now the tabs will touch each other.
06:25Now, as I mentioned earlier, you can use any HTML element to be your tab. Some people prefer
06:29to put divs or anchor tags in here and use float properties; some preferr to use an unordered list.
06:35I like to use spans because as long as I don't have any space in the code, they'll line up
06:39properly and that's the default behavior of a span.
06:42With some of the other approaches we need do a little bit more in the CSS.
06:45And now that we've all our tabs styled, we're going to start styling the panels next.
Collapse this transcript
Styling the main container and the panels
00:00Now we're going to set some CSS properties for the panels.
00:04So in the index.html file in Dreamweaver, let's come over to the CSS Styles panel.
00:09Let's create a new CSS rule.
00:13Make sure we've select a Compound, .sp .panel_container. Let's choose OK.
00:24Let's go over to Background.
00:27We'll set the Background-color to white.
00:30Let's come over to Positioning.
00:32Inside of here we're going to set the Positioning to relative.
00:34We're going to set the Z-Index to 100. That's one number less than what we set the tabs
00:40to, so that the tabs will actually be on top of the panel container.
00:44Let's come down to Overflow, set that to hidden. So as the panels slide inside of the container,
00:49we don't actually see them on the right and left-hand side.
00:51They're look like they're clipped in.
00:53Let's come over to the Box properties.
00:55Let's uncheck Same for all from Margin and for Margin Top,
00:58we're going to say negative 1 at the top margin. That'll actually take the panel container
01:02and move it up 1 pixel.
01:04And again, since it Z-Index is lower than the tabs, it'll actually tuck the panel container
01:09underneath the tabs by 1 pixel.
01:11And then lastly, let's come over to Border, keep checked Same for all for Width, Style and Color.
01:19For Top, let's come down and choose solid. For the Width we'll set 1 pixel, and for the
01:23Color, pound and three Cs and click OK.
01:28Next let's create another rule.
01:29We're going to target the panel content. Compound rule. Tyep .sp .panel_container .panel
01:42.panel_content. Let's choose OK.
01:50What we're going to set in here under the Box properties Padding for all,
01:56let's just set 15 pixels. Then we'll click OK.
01:59And you can see a little bit of space showing up here in Dreamweaver's Design view once
02:03we add that property.
02:05Now to test what we have so far, let's come upto the File menu.
02:08We can choose Save All.
02:10You can preview this in browser or use Dreamweaver's Live view.
02:13I'm going to click on Live view here. Now I can see the tabs showing up here. I can see
02:18the panel container, which is actually overlapping the one pixel here, which is what's giving
02:22us that nice clean single-pixel division between the tabs and the content container.
02:27Then I can see all of the panels spaced out, and I can see the container actually extends
02:31down to encompass all three panels.
02:34So with that working, let's come out with of Live view or come back to Dreamweaver.
02:38Back in the index.html file, let's create two more rules.
02:41First rule we're going to create, it's going to be a compound rule: .sp .panel_container .panels.
02:55I'm going to target the panels container that's holding all the individual panels. Let's choose OK.
03:05Let's come down to Positioning.
03:06We're going to set Position to absolute and we're going to set a top value of 0 pixels for
03:12Placement, and click OK.
03:17Let's create another rule, another compound rule, .sp .panel_container .panel, singular.
03:33We're going to target all of the individual panels themselves. Let's click OK.
03:38Let's come over to positioning.
03:41We're going to set Position to absolute.
03:45Let's come over to the Box properties.
03:46Let's set the height to 400. Then we'll click OK.
03:52Now when we come up and preview in browser or do Live view, the panels should disappear
03:56completely. So what's happening here is the panel container is condensing down because the elements
04:01inside have absolute position properties and in order for us to open this up, we're going
04:05to query the height of individual panels and open the panel container using JavaScript.
04:10So, at this point we have all of our CSS in place for our basic panel.
04:13In the next movie, we'll start writing some JavaScript to target these elements and activate
04:17the panel's behavior.
Collapse this transcript
3. Writing the JavaScript and jQuery
Adding the jQuery document ready
00:00Now we're ready to start working in our JavaScript file.
00:02I'm going to come out of Live view in Dreamweaver here.
00:05You might see that the Design view looks a little messy.
00:08What's happening here is all those panels are rendering on top of each other since they have
00:11absolute-positioned properties.
00:14So from the File menu, let's choose Open, let's go into the mySlidingPanels, let's go into
00:19includes, and let's open sliding_panels.js.
00:22So inside here we can start writing our JavaScript file.
00:26I am going to add a few extra returns in here. And so what we're going to start with is we
00:30want to declare a variable, so we're going to type var panelWidth.
00:38We're going to set that equal to 0, then a semicolon.
00:42So throughout the script, we're going to refer back to this global variable, so that if we
00:46change the width of the panel in CSS, we don't have to go back and change our JavaScript.
00:50Our JavaScript will always go back and reference the panelWidth and then readjust everything.
00:56Next, we're going to add in jQuery's document ready structure, so start with the dollar
01:00sign, beginning and ending parenthesis. Type document inside of the parentheses, outside
01:07of the parentheses .ready, outside a parenthesis semicolon.
01:14Inside of the parentheses for ready, type function, beginning and ending parentheses, beginning
01:21and ending bracket. Let's split that open on the brackets.
01:26So inside of this document ready is everything that's going to happen once the browser has
01:29downloaded all of the HTML. So the first thing we're going to do inside of here is redefine the panel width.
01:34Now that the document is ready, we can use jQuery to find out how wide these sliding
01:38panels are and redefine that panel width variable. Then we can use that later on our scripts.
01:43Now, to target the variable that's outside of this function and global to the document,
01:49we're going to type window.panelWidth, we're going to set that equal to, and then we're going
01:56to query the width of the sliding panels. So dollar sign, beginning and ending parenthesis,
02:03tick mark inside for a string literal, .sp outside of the parentheses .width, another set
02:13of parentheses, and a semicolon.
02:16So now whatever the width of our sliding panels main container is is going to be set to that
02:21value for this panel width variable, and then throughout the rest of our script, as long
02:25as we reference this with window.panelWidth, we can always get access to the width of our sliding panel.
02:30Now with our panel width defined, next we can work on positioning the panels so they're not
02:34all sitting on top of each other.
Collapse this transcript
Lining up the panels in a row
00:00Now the next thing we need to do is take each individual panel and line them up in a line
00:05inside of the panels_container.
00:08So what we're going to do is we're going to look at each one of the individual panels,
00:12see where they are in the lineup, and then position them accordingly.
00:15So let's start by typing dollar sign, beginning and ending parenthesis, tick marks inside
00:21for a string literal. We'll type .panel_container .panel.
00:28So we're going to search for each panel inside of the panel_container.
00:34Outside of the parentheses .each, another set of parentheses, semicolon. Inside of
00:41the parentheses for each, type function, another set of parentheses, beginning and ending bracket.
00:51Split that open on the brackets.
00:53So now inside of the each function we want to target each panel that we find.
00:57So let's start with dollar sign, parentheses, type this inside. Each time an item's found
01:04we're going to reference it as this.
01:05Outside of the parentheses .css, beginning and ending parentheses and a semicolon.
01:13Now inside of the parentheses for CSS let's put a beginning and ending bracket.
01:18This way we can specify multiple CSS properties.
01:23Inside of the brackets, two tick marks for the string literal.
01:25We're going to set the width property outside of the string literal but still inside of
01:30the brackets, colon, and then we want to target the window.panelWidth.
01:34We want to set the width of the panels to match the same as the overall container.
01:39So let's copy window.panelWidth.
01:43Let's paste it right inside up here.
01:44And now we need to add pixels, so I'll type plus sign, two tick marks for a string literal,
01:50and then 'px,' since we need to specify pixels as the CSS property.
01:55Now after the string literal for px, let's hit a comma, and we're going to set a second property.
02:01Two tick marks, type in left. Outside of the string literal let's hit a colon, and
02:10then let's add beginning and ending parentheses, and let's add a plus sign, two tick marks
02:15again and then 'px.'
02:17So what we're going to do here is the left property,
02:20we're going to do a calculation inside up here.
02:22So what we need to calculate here is the individual panel that's been found and multiply it by the panelWidth.
02:29So in order to count the panels that are being found, let's come back in the each statement
02:33inside the function and let's type in the word index.
02:38This tells jQuery to count each item that it finds.
02:41So what we're going to do down inside of the parentheses for left is we're going to type
02:44index, then an asterisk to multiply index times.
02:51Let's come up here and copy the window.panelWidth variable, and let's paste it inside up here.
02:58So the index starts at 0, so the very first item will be 0 times the window.panelWidth,
03:04which will give a 0, so the left property of the first panel will be 0.
03:08So that will be the one that we see.
03:10Then the next time the index runs it will be one, times the panelWidth, so the panel
03:14width we're going to start with 325. The left property for the second panel will be 325,
03:20and then the next one will be 650.
03:23Now that we have the individual panels lining up, what we're going to need to do is take
03:26the panels_container, which holds all the individual panels, and make sure that the width of that
03:31object is wide enough to encompass all of the panels inside.
03:35So inside of each function we're going to type dollar sign, parentheses, inside of
03:41the parentheses tick marks for a string literal, .sp .panels. Outside of the parentheses,
03:50.css, another set of parentheses, semicolon, inside, two tick marks for a string literal.
03:58We're going to set the width, then a comma, and then what we're going to do is making
04:04another calculation here.
04:07Another set of parentheses. We're going to type index+1. Since index is zero by default
04:15we want to make sure that we have an actual integer for the first time this runs.
04:20Outside of the parentheses for index+1 but still inside of the parentheses for CSS,
04:25we're going to multiply this times to window .panelWidth variable, so let's copy that.
04:30Let's come down here after the asterisk, let's paste that, and then let's add our string literal for px.
04:37Plus two tick marks 'px.' So with this in place, we have all of the panels lining up
04:43in a row, and then we have the panels_ container wide enough to encompass all of those lined
04:48up panels. Next, we can activate click events for the tabs.
Collapse this transcript
Assigning click events to the tabs
00:00Now we're going to activate the tabs so our users can click on them.
00:04So it's still inside of the document ready function, make sure you're outside of the
00:09each function for the panel_container.
00:11Let's hit a few returns. Start with a dollar sign, another set of parentheses, tick marks
00:19inside for a string literal, .sp inside of the string literal, space .tabs, space, span.
00:30Outside of the parentheses .each, another set of parentheses and a semicolon.
00:38Inside of the parentheses for each, type function, parentheses, brackets. Let's split that
00:46open on the brackets.
00:48So for each span we find inside of the tabs container, dollar sign, parentheses, type
00:56(this) inside of the parentheses, .on, beginning and ending parentheses, semicolon, two
01:04tick marks inside of the parentheses for on, type click. Outside of the string literal
01:11but still inside of the parentheses for on, comma, space function, another set of parentheses,
01:19another set of brackets. Let's split that open, and then inside we're going to run a
01:24custom function, changePanels, beginning and ending parentheses, then a semicolon.
01:34So this changePanels function is a custom function that we haven't created yet, but
01:38each time you click on an individual span, we're going to run this particular changePanels function.
01:44Now, in addition to calling the changePanels function, we want to send along the index
01:47of the item that was clicked on.
01:49So inside of the parentheses for changePanels, we're going to send this parameter.
01:53So we'll type a dollar sign, beginning and ending parentheses. Inside of the parentheses I'll type this.
02:01Outside of the parentheses for this but still inside of the parentheses for changePanels,
02:05we'll type .index and another set of parentheses.
02:12So jQuery will keep track of the individual item that was clicked and then reference its
02:16own index, and then it will send that along with the changePanels instruction to the custom
02:21function that we will write in the next movie.
Collapse this transcript
Animating the panels based on the tab clicked
00:00Now that we have a click event assigned to all of the spans inside of the tabs container
00:04that call a function called changePanels, let's come up here and copy this function name.
00:11Let's come down on our script. Make sure we're outside of the document ready for jQuery.
00:16Let's type function, space.
00:19Let's paste in that function name, beginning and ending parentheses, beginning and ending bracket.
00:25Let's split that open on the brackets.
00:29Now when we call this changePanels function we're also sending a parameter.
00:33Inside of here we're sending this.index, so this is going to be passed here into our variable
00:38that we're going to define inside of the parentheses.
00:42Let's just call this newIndex.
00:44So now inside of this function, let's hit few returns.
00:50We want to first declare a variable.
00:52We are going to type var. We are going to set newPanelPosition.
01:00We're going to set this equal to--let's type parentheses. Inside we're going to type window.panelWidth,
01:12asterisk. We're going to multiply this times the newIndex. Then outside of the parentheses
01:19we're going to multiply that value by -1, then a semicolon.
01:24This is going to give us the panelWidth that we want to move to the panels_container, and
01:28we're setting a negative number so that it moves towards the left.
01:31Next, let's declare another variable, newPanelHeight.
01:35We're going to set that equal to dollar sign, beginning and ending parentheses, semicolon,
01:46and inside of the parentheses we want to target the panel that's being activated so we know
01:50how high to animate the height container so we can have varying heights on our panels.
01:54So inside of the parentheses two tick marks for string literal, .sp .panel, then
02:00I'll type colon, nth or nth-child, beginning and ending parentheses. And inside of the
02:11parentheses what we're going to do is concatenate the actual index of the child we're looking for.
02:16So inside of here we're going to type two tick marks for a string literal, then two plus
02:20signs inside of here, then inside of the plus signs, two parentheses, then inside of the
02:25parentheses, we're going to take newIndex and we're going to add 1 to it.
02:31Now we're adding 1 here because jQuery's nth child starts with 1, but the index that's
02:37coming down as the new variable when we call this function is going to start from zero.
02:42So we want to make sure that we take that variable and add 1 to it so that the nth-child
02:47matches the index number +1.
02:49Now once we find the activated panel--let's bring our cursor outside of these parentheses here--
02:55we're going to type .find, beginning and ending parenthesis, and we're going to search
03:01for the panel content of the activated panel.
03:05So inside of find, we're going to type two tick marks for string literal, .panel_content,
03:12then outside of those parentheses .height, beginning and ending parentheses.
03:19So now the newPanelHeight variable knows how tall the outermost container needs to be to
03:24encompass all of the content that we put into the panel.
03:27Now with these two variables declared, we can create our animation.
03:29So let's add a few more lines, dollar sign, beginning and ending parentheses, tick
03:35marks for a string literal, .sp .panels.
03:39Outside of the parentheses .animates, another set of parentheses, semicolon, inside of
03:49the parentheses beginning and ending bracket. Inside of the brackets we'll type left, colon.
03:58Let's come up here and copy the newPanelPosition variable name. Then outside of the brackets
04:04comma, put 1000 milliseconds.
04:07That's the amount of time it's going to take to animate to the new position.
04:10Next we'll animate the height, so dollar sign, beginning and ending parenthesis, tick marks
04:17inside for a string literal, .sp .panel_ container, outside of the parentheses .animate, beginning
04:31and ending parentheses, semicolon, inside of the parentheses, beginning and ending bracket,
04:38inside of the brackets height:. Let's come up here and copy the variable name newPanelHeight.
04:47Paste that after the colon, outside of the brackets, comma, 1000 milliseconds.
04:55And to preview this, let's come back to index.html, choose File > Save All.
05:02Let's come into Live view or preview in your browser.
05:04And we won't see anything until we actually click on one of the tabs, so I'll click on Video.
05:09That will animate the panel open. I'm going to scroll up here a little bit.
05:13And now I can click between the individual tabs and we'll see that the content not only
05:17changes height but actually swipes back and forth.
05:19Now, one thing you'll notice notice is that the height of the container is going right
05:23to the very bottom of the content.
05:25Now, we did set padding on the content containers but the overall panel container doesn't account
05:30for that since the items inside are absolute positioned.
05:33So to correct for this, let's come out of Live view or out of your browser.
05:38Let's come back to the sliding panels and up here where we declared the newPanelHeight,
05:43after height, let's come in here.
05:45Let's add a plus and then add 15.
05:49That's the amount of space we want to have at the bottom.
05:52Now let's save our file.
05:53Let's come back and preview it again, and then when we open up our individual panels
05:58we'll now add an extra 15 pixels across the bottom.
06:01So again, that space is not being defined in the padding. We're actually opening that container
06:05up an extra 15 pixels based on the height of the content.
06:10Now that our panels slide back and forth and are height animates to the content inside,
06:14next we'll work on activating the tab's selected state.
Collapse this transcript
Assigning a selected state to the tab clicked
00:00Now we are going to modify our custom function to make sure that the tab we clicked on shows in
00:04its selected state.
00:06So let's come out of Live view.
00:08Let's come back to our sliding_panels.js.
00:11Now, still inside of the changePanels function, after the panel_container animation, let's add a few lines.
00:19Start with a dollar sign, parentheses, tick marks inside for a string literal .sp, space, .tabs
00:28space span, outside of the parentheses .removeClass, another set of parentheses, semicolon, inside
00:41of the parentheses for removeClass tick marks for a string literal. Type selected.
00:48So, every time we click one of the tabs, we are going to take that selected class of all
00:53of them and then we want to add it back onto the one that was clicked.
00:56So on the next line dollar sign, parentheses, tick marks for a string literal .sp, space,
01:03.tabs, space, span, colon, nth-child, another set of parentheses, inside of the parentheses
01:16for nth-child, two tick marks, two plus signs.
01:20We are going to concatenate in the new index number.
01:24So let's come up here to where we declare panelHeight. Let's copy the parentheses with
01:28newIndex+1. Let's come down here and let's paste that inside of the plus signs.
01:34Now, outside of the parentheses for the item we're searching for, type .addClass, another
01:41set of parentheses, then a semicolon, inside of addClass two tick marks for a string literal,
01:49type in selected. Then hit Save.
01:51Now there is one other CSS property we're going to want to set.
01:55Let's switch back to sliding_panels.css.
01:59Let's find the rule that's .sp .tabs span. After position: relative, we want to activate
02:06our cursor for these individual items as well, since the browser won't natively set the pointer
02:11cursor on a span.
02:15So let's add cursor:, space, pointer, then a semicolon.
02:24Now to test this, let's come back to index.html.
02:27Let's choose File > Save All, Preview in Browser or do Live view.
02:32Now in Live view, I can roll over the panels.
02:34I can see my hand cursor.
02:36I can click on a tab. The tab goes into its selected state. We actually turn on that border
02:41at the bottom in the selected class so that we have a one-pixel white border.
02:45Since the tabs container is overlapping the panels container by one pixel, since we set
02:51the panel container to -1 on the top margin, we get the illusion here that this tab is
02:56connecting to this panel. Same thing for Video, same thing for Photography.
03:01Now that we have our user experience working properly, next we'll set an auto-start so
03:05the panel will automatically open up to a specific panel when the page loads.
Collapse this transcript
Setting an autostart on page load
00:00Now we want to have the sliding panel automatically open on page load, so let's come out of Life view.
00:05Let's switch over to sliding_panels.js.
00:08Let's scroll up to the top of the document, and we are going to create a new variable up here.
00:13So after panelWidth, we're going to type var space startPanel.
00:20Let's set that equal to 2, then a semicolon.
00:23Now, we are going to be using jQuery's nth-child, which starts at 1, so setting this to 1 will
00:28start the first panel, 2 and then 3.
00:31So to sort of autostart this, now that we have that variable created, let's scroll down.
00:36After the instruction to set a click event on all the spans, let's hit a few returns.
00:42Make sure you're still inside of the document ready.
00:45We'll type dollar sign, parentheses, tick marks inside for a string literal, .sp, space, .tabs,
00:56space, span:nth-child, another set of parentheses, inside of the parentheses for nth-child, two
01:08more tick marks, two plus signs.
01:10Now, inside of the plus signs, we want to put in the index, which is going to be the value
01:14of the startPanel. So type window.startPanel, then outside of the parentheses for the search
01:24item .trigger, beginning and ending parentheses, semicolon. Inside of the parentheses for trigger, type click.
01:38So again, what's happening here is on browser load it's as if the browser is finding the
01:42nth-child of all of our tabs, finding the item that matches the startPanel number and
01:48actually clicking that item for us.
01:52So to test this, let's come back to index.html.
01:55Let's choose File > Save All and then Preview in Browser or use Live View, and now when the
02:01panel loads, it automatically activates the second tab.
02:04Since we put the selected state for the tabs in the change function as well, the tab automatically
02:09moves to its selected state, panel 2 slides over, and the height of the overall container
02:15opens up to encompass all of the content plus the 15 pixels that we put down here at the bottom.
02:22Now, to show the value of actually putting the panelWidth in a variable, let's come out
02:27of Live View. In our CSS panel, let's double-click on .sp.
02:33Let's come over to the Box properties and let's change the Width from 325 to 500.
02:40We'll click OK, come back into Live view or Preview in Browser, and then notice that the
02:45tab panel works perfectly with the Width set to 500 instead of 325.
02:50All of the contents inside are rearranged and we get exactly the same user experience.
02:55So again, setting the panelWidth as a separate variable gives us the ability to change the
02:59dimensions of the sliding panel without going through and making mathematical recalculations
03:04in our JavaScript file.
03:06So now that we have our basic or generic version of our sliding panel working properly, next
03:11we're going to work on creating some background graphics and start styling some of the content
03:14inside of these panels.
Collapse this transcript
4. Creating Custom Graphics
Creating custom graphics for the panels
00:00Now, if you'd like to customize the graphics that we're going to be using in the background
00:04for the panels, you can come into the Exercise Files and in folder 3, you can open up panel_backgrounds.psd.
00:10Now in the last movie, we set the width of the panel to be 500 pixels.
00:14So what I have done here is brought out a guide that matches the 500 pixel mark, to sort
00:18of give me a sense of how wide my content needs to be.
00:20And there are a few ways you can set up background graphics.
00:23You can actually have the color be a gradient down to a solid color here and then set the
00:28same color for your background for the panel, so maybe you don't have to have your images
00:31quite as tall.
00:33And the other thing you can do is you can actually set other graphics inside.
00:37So for example for the iPad course here, I have an iPad in the right inside here, and
00:41we're actually going to use padding to move or manipulate the panel content to make sure
00:45that the text doesn't overlap these background graphics.
00:49So in the Layers panel, I have the three individual items I'm using for this course, and of course
00:53you can put your own graphics in here and save these out.
00:56So when you have your desired artwork in the canvas area, we're going to come up to the
00:59File menu, choose Save for Web & Devices. We'll come up here and choose JPEG.
01:06Next, you will hit Save.
01:09On the desktop, you are going to mySlidingPanels, going to the images directory and overwrite
01:16any of the individual graphics for ipad_ background, photo_background, or video_background. Or of
01:21course you can make your own file names and just modify the file names we're going to
01:24create in our CSS rules later on in the course.
01:27I'm going to cancel out of here since I want to keep these individual graphics.
01:31So once you have your new graphics in place or if you're going to use the graphics that
01:34were included in the exercise files, in the next movie we can start adding in some custom
01:37classes and then some CSS rules to make use of these graphics.
Collapse this transcript
5. Customizing the Panel Styles
Assigning custom classes to the HTML elements
00:00Now to be able to lock onto individual tabs and panels, to custom style them, we're going
00:04to need to add some classes onto those items.
00:07So in Dreamweaver, in your index.html file, let's come over to Code view, let's scroll
00:12up to the top of the document, and let's add some custom classes onto individual items.
00:17So first, let's start with the individual tabs.
00:20So for the very first span, which is for the iPad course, inside of span, let's add class=ipad.
00:31Let's arrow over to the span for Video, space, add a class of video, and then lastly let's
00:41come over to the span for Photography and add a class of photo.
00:48So now we have a custom class on each tab.
00:51Let's scroll down inside of the panel_container, inside of panels, and let's find each individual panel.
00:59So for class panel for the first one, hit a space.
01:02Let's add a second-class onto here called ipad. Let's scroll down.
01:06Let's find the second one. This one is video. Then let's scroll down and find the third one, space, photo.
01:17So at this point, we have custom classes on all of the tabs and all of the panels.
01:20Next, we can create some CSS rules to target these individual items.
Collapse this transcript
Adding CSS rules for the video panel
00:00Now with index.html file open up in Dreamweaver, let's switch back to Design view, and let's
00:05create our first CSS rule to target the selected state of the Video tab.
00:10So let's come over to the CSS Styles panel. Let's create a new rule.
00:15Let's create a compound rule.
00:18So this is going to be .sp, space, .tabs, space, .video.selected. Let's click OK.
00:32The properties we are going to change inside of here, under Color, for the font color, let's
00:37change this to #ffce6f.
00:43Let's come over to Background color.
00:45We are going to set the background color to #3a3563, and let's come over to Border, uncheck
00:56Same for all, and for the Bottom Border, we are going to set solid, 1 pixel, and the color
01:03here is going to be #354e5c, then click OK.
01:12So now we are going to have a custom style for the selected state of the video tab.
01:17Next, let's create another rule, another compound rule.
01:23This one is going to be .sp, space, .panels, space, .video. Let's click OK.
01:33Let's come down to Background. Under Background-image let's choose Browse.
01:38Let's choose mySlidingPanels from the desktop, let's choose images, and let's choose the
01:43video_background.jpg. Click Choose.
01:48Next, for Background-repeat, let's set no repeat, and let's set 0 on the X and 0 on the Y position.
01:53Let's set another rule, another compound rule. .sp, space, .panels, space, .video, space, .panel_content. Choose OK.
02:14Inside here, under Box Properties, uncheck Same for all for Margin, inside of margin-right of 125 pixels.
02:21This way the content won't extend all the way to the right, and we can see the grapes
02:24in the Background of the JPEG. Choose OK.
02:30Next rule .sp, space, .panels, space, .video, space, .panel_content, space, h2.
02:43We are going to target the heading color. Let's choose OK.
02:50For Color, we are going to come in and set that to black. Choose OK.
02:55Next rule, set to compound, .sp, space, .panels, space, .video, space, .panel_content, space, p.
03:14We are going to target the paragraph tags inside of that.
03:17We want to come in here and set that Color to white. Choose OK.
03:24Then the last rule we are going to create, targeting the anchor tags, we'll type .sp,
03:33space, .panels, .video, space, .panel_content, space, a, targeting the anchor link inside
03:43of there. And for the Color, we are going to put a custom color of #ffce6f, then click OK.
03:56Now to test these custom rules, let's come up to the File menu, let's choose Save All,
04:00and then you can either Preview in Browser or go into Live view.
04:04Our Video panel is still set to show by default.
04:08We can see the background colors here, our bottom border, our gold color here for the
04:12label inside of the selected tab, our Heading 2 showing up in black, our copy showing up
04:18in white, and our anchor link showing up in gold.
04:20And we can also see the 125-pixel margin on the right-hand side, which keeps the text
04:25from overlapping the grapes in the background picture.
04:29Now that we have the Video panel styled, next we'll work on the iPad and the Photography panels.
04:33
Collapse this transcript
Adding CSS rules for remaining panels
00:00Now to style the remaining two panels I have all of those CSS rules in a code snippet.
00:05So in Dreamweaver, let's come out of Live view or come out of Preview in Browser.
00:10Let's come up to the File menu, choose Open.
00:13From the Exercise Files, let's go into folder 2 and open up B-panel-styles.css.
00:18So inside here, I have a whole bunch of CSS rules that target the ipad course panel and
00:24the photo course panel.
00:26So let's come in here and copy all of these rules.
00:30Let's move over to sliding_panels.css, let's scroll down to the bottom of the document,
00:35and let's paste in all of these remaining rules.
00:40Let's come back to index.html.
00:42Let's choose File > Save All and again, either Preview in Browser or you can use Live View.
00:50Now you'll see that each one of these items has custom design for both the selected tab,
00:54the background graphics, the actual style and placement of the content, and the links
00:57down at the bottom.
00:59So here's Photography, here's Video, and here is the iPad course.
01:05So now the sliding panel is complete. In the next movie we're going to take a look at adding
01:08progressive enhancement, where if somebody doesn't have JavaScript enabled or CSS enabled,
01:14we still see all of the individual content.
01:16Now, this is an optional thing that you might or might not want add into your website,
01:20but I have been getting a lot of requests lately for some progressive enhancement techniques in my courses.
01:24So I'm going to show you step by step how we would actually take this course and turn
01:28it into a progressively enhanced user experience.
Collapse this transcript
6. Adding Progressive Enhancement Techniques
Removing CSS rules that hide elements
00:00So the idea behind progressive enhancement is that we want to make sure that we're not
00:03hiding any content with CSS in case the user doesn't have JavaScript enabled.
00:09So what will happen is the user won't be able to actually see the content because the JavaScript
00:13is not enabled and we can't actually show or hide individual pieces.
00:17So the first thing we'll want to do is set the CSS properties in the default state to
00:21hide elements we don't want to see and make sure that everything else shows.
00:26So over in the CSS Styles panel, let's scroll down until we see .sp .tabs.
00:32Let's double-click this rule to edit it. Let's come into the Block properties and let's set
00:36the Display of this item to none and then click OK.
00:40Next let's scroll down and find the .panel_container .panels.
00:47This is where we actually set the absolute position property.
00:50Let's delete this, and let's find the next rule .sp panel_container panel.
00:55Let's delete that as well.
00:57So now in the Design view, if I scroll up and down here, I can see Dreamweaver showing me
01:01what the users will see if they don't have JavaScript enabled.
01:04So each of the panels will still be visible.
01:06They'll have their background graphics and all of this CSS treatments we gave them, but
01:10they won't see is the user experience that lines the panels up in a row, and an animated
01:14interactive user experience.
01:17So now that we've removed all of the CSS properties that inhibit users from seeing content without
01:21JavaScript, in the next movie we'll add the CSS properties back in with JavaScript so
01:26that we know they do have JavaScript and then we can invoke our user experience.
Collapse this transcript
Reassigning CSS rules with JavaScript
00:00Now that we have we disabled the CSS rules that make our user interactive experience
00:04possible, we need to add them back in with JavaScript.
00:07So in Dreamweaver, let's come back to our sliding_ panels.js file, let's scroll up, let's find our document
00:13ready, and the first thing we are going to do in the document ready is set a block property
00:17back onto the tabs container.
00:18So we'll type dollar sign, beginning and ending parentheses, tick marks for a string literal,
00:24.sp, space, .tabs, outside of the parentheses .css, another set of parentheses, semicolon, inside
00:37of the parentheses for css two tick marks for the first string literal. We are going to
00:42type display, outside of the string literal comma, another string literal. Let's put in block.
00:51So we set display none as the default state, and now with JavaScript we are going to go
00:55back and reassign display to block.
00:59After that instruction, let's hit a few returns and let's target the other two items.
01:04So dollar sign, parentheses, two tick marks for a string literal.
01:08We are going to type .sp .panel_container .panel.
01:21Outside of the parentheses, we are going to type .css, parentheses, semicolon.
01:28Now, we need to set multiple CSS properties here, so we need to add a beginning and ending bracket first.
01:33We are first going to reset the position, after the string literal, colon, another string
01:42literal. We are going to set absolute.
01:44Then we are going to hit a comma. Now we need to set the height.
01:51Two tick marks for a string literal, then a colon, two more tick marks, 400 pixels.
02:03Next line dollar, sign parentheses, tick marks inside for a string literal, .sp .panel_container.panels, plural.
02:20Outside of those parentheses .css, beginning and ending parenthesis, semicolon, brackets
02:27inside for multiple properties.
02:29Inside of the brackets, two tick marks, position colon, another string literal, absolute, comma,
02:43next property top, colon, string literal, zero pixels.
02:49So what we are basically doing here is the true rules that we set in our CSS originally
02:55and then removed, we're adding them back in with JavaScript here.
02:59So let's hit File > Save.
03:01Let's come back to index.html.
03:04Let's choose File > Save All to test this.
03:07Now in this case, I am going to come over here and test this in a browser.
03:10I am going to choose Safari.
03:13So now when this loads in Safari, our tabs come back. Our interactive user experience is in place.
03:20But now what I am going to do here is I am going to come up to the Develop menu.
03:23I am going to disable JavaScript and then reload the page and see what this page would
03:28look like if somebody didn't have JavaScript.
03:31So as you can see, we saw exactly what we saw earlier in Dreamweaver. All of the panels stack up.
03:35We see all of the CSS design properties we put in place, but we don't get them stacked up.
03:40We don't see the tabs and we don't see the advanced user experience.
03:44And then of course if we come over here and disable styles altogether, this is exactly
03:48the page somebody would see if they didn't have JavaScript or CSS.
03:52So all of the content would be visible and accessible;
03:55they just wouldn't get the added style and they wouldn't get the advanced user experience
03:58that we get with JavaScript.
03:59So that completes adding the progressive enhancement technique here.
04:03Next we'll talk about how you might want to apply progressive enhancement techniques to
04:07some of my other courses.
Collapse this transcript
Conclusion
Where to go from here
00:00So we just completed adding some progressive enhancement techniques to our sliding tab panel.
00:04There is a few other courses I have in the lynda.com online training library where you
00:08can use these same techniques to progressively enhance those projects.
00:12One is the Homepage Promotional Marquee. This is a series of panels that line up on a horizontal
00:17row--very similar to what we just did in our sliding panels.
00:20So we can actually set this to have all of these panels stack vertically if JavaScript is not enabled.
00:25And the other project is a frequently asked questions listing.
00:28In this course I teach you how to create a collapsible panel where we take one div, in
00:32this case the question, and clicking on it will open the corresponding div, which has
00:36the answer to the related question.
00:39So what you might want to do inside of this particular example is go into the HTML code,
00:44find the div called faq_answers_container, set those to be visible by default in the
00:50CSS, and then use JavaScript to go in and change those FAQ answers' height to be zero.
00:56So any interactive project you are working on that includes HTML, CSS, and JavaScript
01:00can benefit from techniques of taking some of that content, setting the default display,
01:05and then rearranging the CSS properties once your JavaScript has been loaded.
01:10So I wish you all the luck in creating your sliding type panels, and I really appreciate you watching my course.
Collapse this transcript


Suggested courses to watch next:

jQuery Essential Training (4h 9m)
Joe Marini



Are you sure you want to delete this bookmark?

cancel

Bookmark this Tutorial

Name

Description

{0} characters left

Tags

Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading
cancel

bookmark this course

{0} characters left Separate tags with a space. Use quotes around multi-word tags. Suggested Tags:
loading

Error:

go to playlists »

Create new playlist

name:
description:
save cancel

You must be a lynda.com member to watch this video.

Every course in the lynda.com library contains free videos that let you assess the quality of our tutorials before you subscribe—just click on the blue links to watch them. Become a member to access all 98,695 instructional videos.

start free trial learn more

If you are already an active lynda.com member, please log in to access the lynda.com library.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Get access to all lynda.com videos

You are currently signed into your admin account, which doesn't let you view lynda.com videos. For full access to the lynda.com library, log in through iplogin.lynda.com, or sign in through your organization's portal. You may also request a user account by calling 1 1 (888) 335-9632 or emailing us at cs@lynda.com.

Access to lynda.com videos

Your organization has a limited access membership to the lynda.com library that allows access to only a specific, limited selection of courses.

You don't have access to this video.

You're logged in as an account administrator, but your membership is not active.

Contact a Training Solutions Advisor at 1 (888) 335-9632.

How to access this video.

If this course is one of your five classes, then your class currently isn't in session.

If you want to watch this video and it is not part of your class, upgrade your membership for unlimited access to the full library of 1,899 courses anytime, anywhere.

learn more upgrade

You can always watch the free content included in every course.

Questions? Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com.

You don't have access to this video.

You're logged in as an account administrator, but your membership is no longer active. You can still access reports and account information.

To reactivate your account, contact a Training Solutions Advisor at 1 1 (888) 335-9632.

Need help accessing this video?

You can't access this video from your master administrator account.

Call Customer Service at 1 1 (888) 335-9632 or email cs@lynda.com for help accessing this video.


site feedback

Thanks for signing up.

We’ll send you a confirmation email shortly.


By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

By signing up, you’ll receive about four emails per month, including

We’ll only use your email address to send you these mailings.

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked