Solved

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

Posted on 2006-06-10
327 Views
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
Question by:C_J_L
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 1

Accepted Solution

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

ID: 16883051
Hey, thanks a lot!
0

## Featured Post

Question has a verified solution.

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

### Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
###### Suggested Courses
Course of the Month5 days, 3 hours left to enroll