JavaScript
  Home arrow JavaScript arrow Page 4 - Using the DOM to Build Dynamic Shadows wit...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Using the DOM to Build Dynamic Shadows with JavaScript and CSS
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating:  stars stars stars stars stars / 0
    2009-07-06

    Table of Contents:
  • Using the DOM to Build Dynamic Shadows with JavaScript and CSS
  • Reviewing some previous shadowing techniques
  • Creating dynamic shadows with the DOM
  • The shading application’s full source code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


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

    <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 JavaScript (fixed size)</title>

    <script language="javascript">

    function addShadow(){

    var mainCont=document.getElementById('maincontainer');

    if(!mainCont){return};

    var shadow=document.createElement('div');

    mainCont.appendChild(shadow);

    shadow.id='shadow';

    }

    window.onload=function(){

    if(document.createElement&&document.getElementById&&document.getElementsByTagName){

    addShadow();

    }

    }

    </script>

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

    margin: 0;

    }

    #maincontainer{

    position: relative;

    width: 350px;

    margin-left: auto;

    margin-right: auto;

    z-index: 1;

    }

    #textcontainer{

    position: absolute;

    padding: 10px;

    background: #ccc;

    z-index: 2;

    }

    #shadow{

    position: absolute;

    left: 4px;

    top: 4px;

    width: 340px;

    height: 310px;

    background: #999;

    z-index: 0;

    }

    </style>

    </head>

    <body>

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

       · This chapter of the series shows how to use a proper combination of the DOM and CSS...
     

    JAVASCRIPT ARTICLES

    - Comparing Fields and Customizing Error Messa...
    - Checking Numbers and File Extensions with jQ...
    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek