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

Building `Drag-and-Drop` DIVs: Polishing the Look and Feel
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    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

    - 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
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT