From the course: Interactive Animations with CSS and JavaScript
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Add a JavaScript event handler
From the course: Interactive Animations with CSS and JavaScript
Add a JavaScript event handler
- [Instructor] Now that we've got our styling mechanism in place to be able to switch from one slide to the other, let's write some JavaScript code to actually do the transition. So I'm going to add some event handlers. Let's go back into our project. And we're gonna open up our JavaScript file, which till now has been empty. Now, first of all, I have to have a good place to add my event handler, and if you've used jQuery, things like that, there are ways to register a function that gets called when the page is loaded. In this case, I'm gonna use plain JavaScript, and I'm gonna use a window. I'm gonna add event listener to the DOM content loaded event. And that's a little different than what most people do, but the good news about DOM content loaded is that it's called immediately as soon as the DOM has been parsed and your page is constructed. It doesn't wait for all the resources to be downloaded. And in this case, since we're not playing with images or media, we can just go ahead…
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.