Solved

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

Posted on 2006-06-10
2
323 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

829 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