Solved

Find y position of bottom of element on web page and determine how much space is left

Posted on 2006-06-10
2
318 Views
Last Modified: 2008-02-01
I need to be able to find the position of the bottom of a tabstrip on a webpage in order to determine how much space is left in the window clientheight space. Then I will add a division to what area is left based on the user's window size. This area will have a scroll bar and must be visible without using the browser scroll bar on the right.
The tabstrip is displayed. When a user clicks on a specific tab, a dynamic table will be displayed in the remaining area. The table is larger than the window size so the division around the table places a scrollbar at the bottom and right. I want to dynamically calculate this area no matter what the user's window size is.

TAB1    Tab2   Tab3 Tab4 Tab5
---------------------------------------------------------------------------------------------------------------------------------
table                                                                                                                                                          I    *
                                                                                                                                                                 I    *
                                                                                                                                                                 I    *
                                                                                                                              division right scroll bar        *
                                                                                                                                                                 I    *
division scroll bar---------------------------------------------------------------------------------------------------------------  *
browser scroll bar***********************************************************************

0
Comment
Question by:C_J_L
2 Comments
 
LVL 1

Accepted Solution

by:
sganjam earned 500 total points
ID: 16882297
function PosX(obj){
      var curleft = 0;
      if (obj.offsetParent)
      {
            while (obj.offsetParent)
            {
                  curleft += obj.offsetLeft
                  obj = obj.offsetParent;
            }
      }
      else if (obj.x)
            curleft += obj.x;
               return curleft;
}

function PosY(obj){
                var curtop = 0;
      if (obj.offsetParent)
      {
            while (obj.offsetParent)
            {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
            }
      }
      else if (obj.y)
            curtop += obj.y;
      return curtop;
}

The above two functions will calculate the  X (from left) and Y (from top) position of the Top-Left corner of the object in pixels . You can then manipulate it by adding on the object width or height. Use the following:

obj.offsetheight (for height of the object)
obj.offsetwidth (for width of the object)

You can also use

document.body.offsetWidth
document.body.offsetHeight

For the screen width and height respectively. Just make sure to define an arbitrary width and height to the body tag.

If you wanted to for example, calculate the the position of an object from the right side of the screen:

offsetRight = document.body.offsetWidth - (offsetX + p.offsetWidth);
0
 

Author Comment

by:C_J_L
ID: 16883051
Hey, thanks a lot!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 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

15 Experts available now in Live!

Get 1:1 Help Now