Home arrow JavaScript arrow Page 2 - Building `Drag-and-Drop` DIVs: Polishing the Look and Feel
JAVASCRIPT

Building `Drag-and-Drop` DIVs: Polishing the Look and Feel


This is the last tutorial of the series “Building drag-and-drop DIVs.” Welcome back. In three parts, this series introduces the key points for creating dragging DIV elements, for quick inclusion in web pages, emulating the behavior of many user interfaces found in current desktop applications.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 8
December 21, 2005
TABLE OF CONTENTS:
  1. · Building `Drag-and-Drop` DIVs: Polishing the Look and Feel
  2. · Adding elements on the fly: building DIV elements with the DOM
  3. · Nesting and styling DIV elements: defining the “DOMWindow()” function
  4. · Turning DOM-based DIVS into dragging elements: using the X library
  5. · Putting the pieces together: listing the full code for DOM-based dragging DIVs

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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.


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 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials