Solved

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

Posted on 2006-06-10
2
316 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
Comment Utility
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
Comment Utility
Hey, thanks a lot!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

763 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

10 Experts available now in Live!

Get 1:1 Help Now