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

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 / 15
December 21, 2005
  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

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

- Project Nashorn to Make Java, JavaScript Wor...
- JavaScript Virus Attacks Tumblr Blogs
- Google Releases Stable Dart Version, JavaScr...
- Khan Academy Unveils New JavaScript Learning...
- Accessing Nitro? There`s an App for That
- JQuery 2.0 Leaving Older IE Versions Behind
- Fastest JavaScript Engine Might Surprise You
- Microsoft Adjusting Chakra for IE 10
- Brendan Eich: We Don`t Need Google Native Cl...
- An Overview of JavaScript Statements
- An Overview of JavaScript Operators
- Overview of JavaScript Variables
- More of the Top jQuery Social Plugins
- The Top jQuery Social Plugins
- More of the Top jQuery Slider Plugins

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials