Solved

Drag the divider to increase/decrease the width of the left / right or top/bottom  area.

Posted on 2008-06-16
3
419 Views
Last Modified: 2012-05-05
I wanted to implement in java script a horizontal and vertical divider between the 2 windows (or divs) such that - once you drag the divider - it should increase/decrease the width of the left / right or top / bottom  area.

Say for example - in Lotus Notes client - there are 2 dividers 1 vertical and 1 horizontal - vertical divider separates the folder structure and the mails in that folder - and when this divider is dragged it increase / decreases the left and the right area.
Horizontal divider separates the mails and the contents of each mail.
0
Comment
Question by:dnraj
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
Lolly-Ink earned 500 total points
ID: 21800639
This is a vertical splitter I implemented some time ago. It was made and tested for Internet Explorer only.
<html>

   <style>

      body

      {

         margin: 0;

         overflow: hidden;

      }
 

      div

      {

         height:  100%;

         overflow: auto;

      }
 

      div.left

      {

         background: gold;

         float:      left;

         width:      300px;

         clear:      left;

         cursor:     default;

      }
 

      div.right

      {

         background: salmon;

         float:      left;

         clear:      right;

         cursor:     default;

      }
 

      div.splitter

      {

         background: silver;

         width:      4px;

         cursor:     e-resize;

         float:      left;

      }

   </style>
 

   <script>

      var _divElement   = [];

      var _unselectable = [];

      var _cursor       = [];

      var _mouseDown    = false;

      var _x;

      var _xOriginal;

      var _widthSplitter;
 

      function init()

      {

         _divElement                        = document.getElementsByTagName("div");

         _x                                 = _divElement["divLeft"].style.width;

         _widthSplitter                     = _divElement["divSplitter"].style.width;

         var spanElement                    = document.getElementsByTagName("span");

         spanElement["spanLeft"].innerHTML  = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Curabitur blandit diam sed ante. Cras sollicitudin nisl et dolor. Quisque mattis dui vel diam faucibus varius. Curabitur eu sem. Praesent eu lectus non lacus pellentesque vehicula. Curabitur sed dui dapibus neque posuere mattis. Maecenas lorem diam, tempor eget, aliquam et, iaculis ac, odio. Praesent magna nulla, dignissim dictum, ultrices in, ullamcorper a, mi. In dictum gravida leo. Ut consequat, est non sollicitudin lacinia, enim justo aliquam sem, eget euismod sem erat nec ligula. Cras a metus. Pellentesque viverra. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus dictum molestie orci. Donec a odio. Phasellus pretium quam et eros. Duis nisi.";

         spanElement["spanRight"].innerHTML = spanElement["spanLeft"].innerHTML;

      }
 

      function mouseDown()

      {

         if (event.button == 1)

         {

            _mouseDown = true;

            _x         = event.x;

            _xOriginal = _x;

            for (var index = 0; index < document.all.length; index++)

            {

               _unselectable[index]             = document.all[index].unselectable;

               document.all[index].unselectable = "on";
 

               _cursor[index]                   = document.all[index].style.cursor;

               document.all[index].style.cursor = "e-resize";

            }

         }

      }
 

      function mouseMove()

      {

         if (_mouseDown && (_x != event.x))

         {

            _x = event.x;

            split(_x);

         }

      }
 

      function split(x)

      {

         _divElement["divLeft"].style.width  = x;

         _divElement["divRight"].style.width = document.body.clientWidth - x - _widthSplitter;

      }
 

      function cancelSplit(reset)

      {

         if (_mouseDown)

         {

            _mouseDown = false;

            if (reset)

            {

               split(_xOriginal);

            }

            for (var index = 0; index < document.all.length; index++)

            {

               document.all[index].unselectable = _unselectable[index];

               document.all[index].style.cursor = _cursor[index];

            }

         }

      }
 

      function keyDown()

      {

         if (event.keyCode == 27)

         {

            cancelSplit(true);

         }

      }
 

      function resize()

      {

         split(_x);

      }

   </script>

   <body onload="init()" onkeydown="keyDown()" onresize="resize()">

      <div id="divParent" onmousemove="mouseMove()" onmouseup="cancelSplit(false)" onmouseleave="cancelSplit(false)">

         <div id="divLeft" class="left">

            <span id="spanLeft"></span>

         </div>

         <div id="divRight" class="right">

            <div id="divSplitter" class="splitter" onmousedown="mouseDown()"></div>

            <span id="spanRight"></span>

         </div>

      </div>

   </body>

</html>

Open in new window

0
 

Author Comment

by:dnraj
ID: 21892674
Thank you - I will be implementing it shortly
0
 

Author Comment

by:dnraj
ID: 22259524
Thanks for the solution. It was helpful
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Detecting robots? 5 35
Understanding Trigger in Jquery 10 28
Two RegEx conditions in one 3 17
Asp.net mvc foreach 3 6
As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now