Using the DOM to Build Dynamic Shadows with JavaScript and CSS
(Page 1 of 4 )
A proper combination of JavaScript code and CSS styles can be the perfect recipe for incorporating eye-catching effects into a certain number of elements included in a given web document. This three-part series of articles walks you through creating dynamic shadows using unobtrusive client-side scripting, so if you’re interested in learning how to implement this visual effect within your own web pages, then you’ve come to the right place.
Introduction
Welcome to the second part of the series. As I said above, this series shows you different approaches for building pretty realistic shadows using JavaScript and some basic CSS styles. It complements the theoretical side of this topic with illustrative hands-on examples.
If you already went through the first installment of this series, then it’s quite probable that creating basic shading effects utilizing some simple CSS styles is now familiar to you. In that specific tutorial I provided you with a few examples that showed you how to achieve this neat effect with minor hassles.
First I showed you how to incorporate a basic shadow into a targeted DIV within a sample web page by using just a background image, which was properly attached to the DIV in question via CSS.
While this approach probably is the simplest to implement, it comes with plenty of limitations. It can only be applied in certain cases where the web page element that will be linked to the shadow has fixed dimensions. This is actually a very unusual situation.
However, I also showed you how to build basic shading effects by tweaking the “border-style” property of a DIV, in this case by specifying an “outset” value for its border CSS property. Nonetheless, the results achieved with this technique are rather unreliable, since each browser displays the border property of a given element in different ways, which severely restricts the use of this method.
Not all is lost, though, when it comes to including dynamic shadows in a web document. Actually, there are some other approaches that use a combination of clean JavaScript and CSS styles that can be implemented with relative ease. Therefore, in this second article of the series, I’ll be taking a close look at them, and show you how to use them to incorporate realistic shadows into different elements of a web page.
As you’ll see for yourself in the next few lines, these methods will use a proper combination of the DOM and CSS to build dynamic shadows, so go ahead and start reading now!
Next: Reviewing some previous shadowing techniques >>
More JavaScript Articles
More By Alejandro Gervasio