JavaScript
  Home arrow JavaScript arrow Page 2 - Building `Drag-and-Drop` DIVs: Polishing t...
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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? 
JAVASCRIPT

Building `Drag-and-Drop` DIVs: Polishing the Look and Feel
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 7
    2005-12-21

    Table of Contents:
  • Building `Drag-and-Drop` DIVs: Polishing the Look and Feel
  • Adding elements on the fly: building DIV elements with the DOM
  • Nesting and styling DIV elements: defining the “DOMWindow()” function
  • Turning DOM-based DIVS into dragging elements: using the X library
  • Putting the pieces together: listing the full code for DOM-based dragging DIVs

  • 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


    Building `Drag-and-Drop` DIVs: Polishing the Look and Feel - Adding elements on the fly: building DIV elements with the DOM


    (Page 2 of 5 )

    Making dragging DIVs look like regular windows requires performing some fine-tuning tasks, in order to control the appearance of their borders and create a realistic beveled effect. Inspired by an excellent script written by Scott Andrew, I’ll build a window-like DIV element by utilizing three different boxes, which when appropriately positioned, will look similar to a conventional window.

    Before I begin creating the corresponding DIVs, a brief note is in order here: the approach that I’ll take uses the DOM and some presentational JavaScript for creating the pertinent DIVs. However, you can go through an alternative approximation and use regular CSS styles and (X)HTML markup, in order to build window-like dragging DIVs. That said, I’ll first define a simple JavaScript function, which utilizes the DOM for creating a DIV element. Below is the corresponding signature:

    function DOMDiv(x,y,w,h,col){
     var div=document.createElement('div');
       div.style.position='absolute';
       div.style.left=x+'px';
       div.style.top=y+'px';
       div.style.width=w+'px';
       div.style.height=h+'px';
       div.style.backgroundColor=col;
       div.style.padding='0';
       return div;
    }

    As you can see, the function shown above takes a few input parameters, in order to build a DIV element, and adds some styles to it, specifying its width, height, top-level coordinates and background color. Finally, the function returns the styled DIV to the calling code. Indeed, this function is actually simple to understand.

    At this point, you might be wondering…what’s the reason for writing this function? As I said before, the complete window-like dragging DIV will be comprised of three DIV elements, so I’ll use this function for constructing each one of them.

    Having defined the “DOMDiv()” function, let’s move on and look at another one, “DOMWindow()”, which, as you’ll see in short, is responsible for creating the three DIV elements mentioned before, as well as for adding the proper styles to each of them, in order give the whole structure the look and feel of a regular window.

    More JavaScript Articles
    More By Alejandro Gervasio


       · In this last part of the series, the powerful functionality of the X library is...
     

    JAVASCRIPT ARTICLES

    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway