Home arrow JavaScript arrow Page 2 - Using the DOM to Build Dynamic Shadows with JavaScript and CSS
JAVASCRIPT

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.

Author Info:
By: Alejandro Gervasio
Rating:  stars stars stars stars stars / 0
July 06, 2009
TABLE OF CONTENTS:
  1. · Using the DOM to Build Dynamic Shadows with JavaScript and CSS
  2. · Reviewing some previous shadowing techniques
  3. · Creating dynamic shadows with the DOM
  4. · The shading application’s full source code

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the DOM to Build Dynamic Shadows with JavaScript and CSS - Reviewing some previous shadowing techniques
(Page 2 of 4 )

Before I show you how to use the assistance of JavaScript and CSS to build some pretty realistic shadows in selected elements of a given web document, I’d like to list the code samples developed in the first article of the series.

By doing this, you’ll be able to evaluate the pros and cons of the aforementioned techniques against the DOM-based approach that I plan to implement later on.

Having said that, here are all the practical examples that you learned in the prior tutorial, accompanied by their corresponding screen shots:  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example of shadowed DIV using one background image</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

text-align: center;

margin: 0;

font: bold 16pt Arial, Helvetica, sans-serif;

color: #000;

}

p{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #000;

}

#container{

width: 350px;

height: 300px;

padding: 10px;

margin-left: auto;

margin-right: auto;

background: #fff url(shadow.gif) center center no-repeat;

}

</style>

</head>

<body>

<h1>Example of shadowed DIV using one background image</h1>

<div id="container">

<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>

</body>

</html>

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example of shadowed DIV using the outset border property (fixed size)</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

text-align: center;

margin: 0;

font: bold 16pt Arial, Helvetica, sans-serif;

color: #000;

}

p{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #000;

}

#container{

width: 350px;

padding: 10px;

margin-left: auto;

margin-right: auto;

background: #ccc;

border: 3px outset #fff;

}

</style>

</head>

<body>

<h1>Example of shadowed DIV using the outset border property</h1>

<div id="container">

<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>

</body>

</html>

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Example of shadowed DIV using the outset border property (liquid size)</title>

<style type="text/css">

body{

padding: 0;

margin: 0;

background: #fff;

}

h1{

text-align: center;

margin: 0;

font: bold 16pt Arial, Helvetica, sans-serif;

color: #000;

}

p{

font: normal 10pt Arial, Helvetica, sans-serif;

color: #000;

}

#container{

width: 30%;

padding: 10px;

margin-left: auto;

margin-right: auto;

background: #ccc;

border: 2px outset #fff;

}

</style>

</head>

<body>

<h1>Example of shadowed DIV using the outset border property (liquid size)</h1>

<div id="container">

<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>

</body>

</html>

 

 

As you’ll surely recall, the first hands-on example implements a quick and dirty approach to incorporating a basic shadow into a given DIV. In this case, the technique is based on including a shadowed background image into the element in question, thus achieving the visual effect.

With reference to the other two examples, they merely tweak the “border-style” property of a couple of DIVs to drop a shadow, using both fixed and liquid dimensions. Logically, all of the previous examples are extremely simple to grasp, so you shouldn’t have major problems understanding how they function.

So far, so good. Now that you hopefully recalled how all of these CSS approaches were implemented to include basic shadows in a web document, it’s time to see how to use a combination of DOM scripting and a few CSS styles to create more efficient and realistic dynamic shadowing effects.

Naturally, to see how this DOM-driven technique will be developed, you’ll have to click on the link below and keep reading.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials