Using the DOM to Build Dynamic Shadows with JavaScript and CSS
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.
Using the DOM to Build Dynamic Shadows with JavaScript and CSS - The shading application’s full source code (Page 4 of 4 )
As I said in the section that you just read, here’s the complete source code corresponding to this simple JavaScript application, which uses some basic CSS styles along with the DOM to incorporate a dynamic shadow into a given web page element:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<h1>Example of shadowed DIV using JavaScript (fixed size)</h1>
<div id="maincontainer">
<div id="textcontainer">
<p>Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here. Content for DIV element goes here.</p>
</div>
</div>
</body>
</html>
That’s all for the moment concerning the creation of dynamic shadows with the DOM. Of course, feel free to introduce your own modifications to all of the code samples developed in this tutorial, to improve your existing skills in incorporating this visual effect into your web sites.
Final thoughts
In this second tutorial of the series, you hopefully learned the basics of using the DOM, along with some basic CSS styles, to build dynamic shadows, which can be easily attached to any element of a web document.
Nonetheless, it’s necessary to implement this approach in the context of a real-world situation. In the last part of this series, then, I’m going to teach you how to incorporate this simple shading effect into an existing image gallery.
Now that you know what the upcoming tutorial will be about, you won’t want to miss it!
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.