Solution: Create a pause screen
Video: Solution: Create a pause screenHere'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.
- Next steps
Viewers: in countries Watching now:
Follow along with author Justin Putney as he uses open technologies (HTML5, jQuery, and CSS) to create a dynamic presentation slideshow that responds to mobile and desktop layouts. Learn to customize the slideshow to fit your next project, and to display artwork, photography, and other kinds of content.
Discover how to structure the HTML and slide content; design the navigation to react to clicks, keyboard input, and swipe gestures; and use CSS to customize the slide display for different screens and animated transitions. Justin also includes a series of challenge-and-solution pairs to test your skills.
Then, when you're ready, watch the HTML5 Projects: Creating an Advanced Responsive Presentation follow-up course to enhance your web presentation slides with audio, video, and an automatic playback feature.
- Structuring an HTML5 slideshow
- Creating the default slide appearance
- Using jQuery to display the current page
- Adding swipe gestures for mobile
- Creating a pause screen
- Translating your ideas into CSS
- Using media queries to adjust the layout
Solution: Create a pause screen
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.
There are currently no FAQs about HTML5 Projects: Creating a Responsive Presentation.