From the course: Interactive Animations with CSS and JavaScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Add a JavaScript event handler

Add a JavaScript event handler

From the course: Interactive Animations with CSS and JavaScript

Start my 1-month free trial

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…

Contents