DHTML
  Home arrow DHTML arrow Page 2 - A Close Look at the Scriptaculous DHTML Li...
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 
Sun Developer Network 
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? 
DHTML

A Close Look at the Scriptaculous DHTML Library
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2007-04-04

    Table of Contents:
  • A Close Look at the Scriptaculous DHTML Library
  • Creating basic DHTML effects with Scriptaculous
  • Using other core DHTML effects
  • Getting the most out of the MoveBy DHTML effect

  • 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


    A Close Look at the Scriptaculous DHTML Library - Creating basic DHTML effects with Scriptaculous


    (Page 2 of 4 )

    As mentioned in the introduction that you just read, the Scriptaculous framework comes equipped with a robust set of DHTML objects for incorporating eye-catching effects into any web document.

    Having said that, I'm going to show you some instructive examples that will demonstrate how to use what in the Scriptaculous context are called "core effects." Take a look at the first example. It shows how to use one of these basic effects. In this case, I'm talking about the one called "Opacity," and a primitive implementation of it can be coded as follows:

    <!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 Opacity effect</title>
       
    <script language="javascript"
    src="scriptaculous/js/prototype.js"></script>
       
    <script language="javascript"
    src="scriptaculous/js/scriptaculous.js"></script>
       
    <script language="javascript">
         
    // display effect
         
    function displayEffect(){
             new Effect.Opacity('container',{duration:0.8, from:1.0,
    to:0.1});
         
    }
         
    function initializeElement(){
             Event.observe
    ($('container'),'click',displayEffect,false);
         
    }
         
    Event.observe(window,'load',initializeElement,false);
        
    </script>
       
    <style type="text/css">
         
    #container{
     
           width: 300px;
            height: 100px;
            padding: 10px;
            background: #cf9;
            font: normal 11px Verdana, Arial, Helvetica, sans-serif;
            color: #000;
            text-align: center;
            border: 1px solid #999;
         
    }
        
    </style>
     
    </head>
     
    <body>
       
    <div id="container">This element is going to fade now!</div>
     
    </body>
    </html>

    As demonstrated above, creating an "Opacity" effect with Scriptaculous is indeed a straightforward process that can be performed with minor effort. In this case, I also used the Prototype framework (bundled with the complete Scriptaculous package) to assign this core effect to a sample DIV element, identified as a "container."

    You should notice that the effect in question has been assigned via the "Effect.Opacity" object, which accepts some useful parameters, such as the ID of the web page element to which the effect will be applied, and the corresponding duration. Of course, as you may have guessed, if you test the previous example on your browser, you'll see a green DIV that fades out slowly.

    Okay, as you saw previously, creating basic effects with Scriptaculous is a rather simple task. Now I will show you another core effect that comes bundled with this library. In this case, I'm speaking of an effect called "Scale," which can be used as indicated below:

    <!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 Scale effect</title>
       
    <script language="javascript"
    src="scriptaculous/js/prototype.js"></script>
       
    <script language="javascript"
    src="scriptaculous/js/scriptaculous.js"></script>
       
    <script language="javascript">
         
    // display effect
         
    function displayEffect(){
             new Effect.Scale('container',150);
         
    }
         
    function initializeElement(){
             Event.observe($('container'),'click',displayEffect,false);
         
    }
         
    Event.observe(window,'load',initializeElement,false);
        
    </script>
       
    <style type="text/css">
         
    #container{
            width: 300px;
       
        height: 100px;
            padding: 10px;
            background: #cf9;
            font: normal 11px Verdana, Arial, Helvetica, sans-serif;
            color: #000;
            text-align: center;
            border: 1px solid #999;
         
    }
        
    </style>
     
    </head>
     
    <body>
       
    <div id="container">This element is going to scale now!
        </div>
     
    </body>
    </html>

    If you examine the above example, you'll realize that I followed an approach very similar to the one used to demonstrate the functionality of the first effect. In this case, there's a new effect called "Scale," which obviously scales a specified web page element.

    In this situation, if you test the previous (X)HTML file, you'll see how the same DIV that was used in the first example is scaled up progressively. Quite easy to do, isn't it?

    So far, so good. At this point you've grasped the logic required to use some core DHTML effects that take advantage of the capacity offered by the Scriptaculous framework. Nonetheless, this is only the beginning of this journey, since there are many more effects to cover here. They'll be treated in the course of the section to come.

    To see how these brand new DHTML effects can be coded with this powerful JavaScript library, please keep reading.

    More DHTML Articles
    More By Alejandro Gervasio


       · Over the course of this first tutorial of the series, you'll see how to use the set...
       · Excellent work. Very easy to follow. Keep up the good work.
       · Thank you for the kind comments on my article. I truly appreciate them, and sure...
     

    DHTML ARTICLES

    - Text-Justify, Volume, and Other Style Sheet ...
    - Ruby-Position, Size, and Other Style Sheet P...
    - Padding, Pages, and More Style Sheet Propert...
    - Marks, Orphans, and More Style Sheet Propert...
    - Layouts, Margins, and Other Style Sheet Prop...
    - Floats, Fonts, and Other Style Sheet Propert...
    - Color, Filters, and Other Style Sheet Proper...
    - Borders and More with Style Sheets
    - Learning Style Sheet Properties
    - Style Sheet Property Reference
    - Completing a Noisy Image Application
    - An Object-Based Approach to Building Noisy I...
    - A Basic Method for Building Noisy Images
    - Adding More Features to Sliders with the Scr...
    - Using Sliders with the Scriptaculous Framewo...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT