Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Here's the solution I came up with. It is in the browser right now. And I'm just going to hit the W key on my keyboard and then it fades to white. Hit the W key again. It comes right back. And this works on any slide. Hit the W key. And fades back in when I hit it again so the way I started to think about this was first of all what is it I'm wanting to change or hide. You know, it's easiest to just hide something and display what's behind it and so in this case, if I hid an individual slide, I'm going to see the background for the slides container, which is this gradient, and I want to go to white.
Well, what's white? Well, the body by default of the HTML document is white, and that's sitting behind that. So why don't I just go ahead and hide the whole slide container, that's simpler. So I was kind of working with that thought to begin with. And one of the first things I needed to do was get the key code for the W key. So I came back down here to the type something field in the handy dandy key up documentation of jQuery. Hit the W key. Found the key code was 87 so that's good. We'll use that in a moment.
And then I started to think, you know, how do I go about turning, not only hiding it but then showing again, and I remember jQuery is able to toggle things. So I just went looking for this function of toggle visibility. I thought maybe there's a toggle visibility because there's, you know, multiple things you want to toggle. So I didn't find anything. The next step, I put a space in there. I thought, you know, maybe that'll be more inclusive. And lo and behold I found the toggle function. Display or hide the matched elements. So that sounds like exactly what I want.
And there's a bunch different ways to implement the toggle function. I can apply a duration and get a complete function as a call back. I could pass an object with several options in it. And I just kept scrolling as I was looking at this and oh, I could say show or hide. Well, that's useful, that's what I'm looking for and I read this and said, you know, just calling it with no parameters toggles the visibility of the elements. Oh, so that's perfect, that's what I'm looking for. I'll switch over to Dreamweaver and show you how I did that.
So, here's the completed code. I'm going to roll it back and show you what it looked like at the point we're at. So I just plopped on another else if statement and put my key code in as 87. And so I grab this whole slides container object and what I said was toggle. I'm just going to save that and switch back. And so you can see what this looks like when I hit the W key, it just goes to white. Hit it again, and it comes back. So then I did some more searching in the documentation and I thought, you know, that's kind of abrupt, maybe just a nice little fade would work. And jQuery happens to have a function that does this. I could also just pass a duration in there, but I'll save that and then I'll refresh it and I'm going to hit the W key and there it is, a nice fade. So that was just one line of code.
If we wanted to fade to black, maybe we'd have either another object or we would set the background color of the body to black or something like that. That would be the only difference. Really, it's pretty simple and we could do that with just another line here and go back to our key up and we just look for what the V key code would be. So you can see there's a lot of flexibility there. You can do a lot with that and it doesn't necessarily take a lot of code.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105138 Viewers
56 Video lessons · 116919 Viewers
71 Video lessons · 86127 Viewers
131 Video lessons · 41185 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.