![]() arguments is an Array-like object corresponding to the arguments passed to a function. In case you’re not a JavaScript ninja, you may want to learn how I enabled this method to accept an arbitrary number of objects by using arguments. The extend method is a simplified version of its namesake in jQuery, and it’s used to merge the properties of two or more objects into one (the first parameter). It defines only two methods: extend and buildUrl. ![]() It contains methods that are of general interest and that our JavaScript modules will use. The first module we’ll discuss is the utility module. With these points in mind, let’s take a look at the modules defined. Finally, each file implements the module pattern. For example, it eliminates some JavaScript silent errors by changing them to throw errors. The second is that, in each module, I’ve employed strict mode, which enforces more restrictive rules for how the JavaScript code is executed. The first is that each module is defined using an IIFE (Immediately-Invoked Function Expression), allowing us to create private variables and methods and to avoid polluting the global scope. This file is where we’ll define the event handlers for the buttons of the gallery, what happens when a user clicks one of the links in the pager, and what to do when the user searches for some given text.īefore we examine the peculiarities of each module, I want to highlight a few interesting techniques I’ve used. The business logic of the project is also organized into small modules, with one file – main.js – acting as the glue between the markup and the JavaScript modules. ![]() With this last module, we’ve completed the overview of the CSS files used to style the project, so it’s now time to discuss the business logic. The full code of the homepage.css file is presented below. When dealing with real-world projects, you’ll often find yourself styling elements that have a certain look only on a given page, and in such cases it makes sense to create a specific CSS file just for that page. Here is where we style elements of the project that don’t fit any of the other modules and that are specific to the homepage. The full code for this module is as follows. The other point worth a mention is that there is an effect that takes place when a thumbnail is hovered or focused to enhance the accessibility, as discussed in the previous section. It forces the thumbnails to be five in a row by setting the width property to 19%, a margin-right of 1%, and the display property to inline-block. The thumbnails module doesn’t contain anything too fancy. The full code of this module is presented below. ![]() In case you consider yourself a beginner with CSS, you might also want to study how the buttons are made circular and how the arrows are drawn. Styling for the focus event is important because it enhances the accessibility of an element for those users navigating the website via the keyboard (for example, by hitting the TAB key). The second point is that we define how the style of the arrows changes when users hover over or focus on them. By doing so, we ensure that the image doesn’t overflow the container. Then, the img element inside it – used to show the selected image – is constrained by setting its max-height and max-width property to 100%. The first point is that the element with a class of gallery, which acts as a container for the photo shown in its natural size, is given a fixed height of 500px. It’s made of simple declarations, and I’ll highlight a few points of interest. The gallery module defines the styles of the gallery and its components. In the previous article, we discussed the module of the helper classes and the layout modules. ![]()
0 Comments
Leave a Reply. |