Control coordinates on screen

This is a discussion on "Control coordinates on screen" within the JavaScript Forum section. This forum, and the thread "Control coordinates on screen are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 8th, 2008, 10:07
New Member
Join Date: Feb 2008
Location: Brindisi (Italy)
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Control coordinates on screen

Hi to all,
my problem was to detect the coordinates for each control on the web page. Since I was not successful in finding any property to retrieve
such information, I wrote the following code to get it out.
The code follows at the bottom of this post.
Basically, one calls getOBJfunction( id, "top" ) and getOBJfunction( id, "left" ) to retrieve the Y and X coordinate of the control within the
webpage. The parameter id indicates the id property of the given control,
according to the nomenclature used along the web page.
Thus, for example, the position of <INPUT ID="item1"> can be
tracked down via
* getOBJposition( "item1", "top" );
* getOBJposition( "item1", "left" );
My personal use is to place floating divs over the screen and in particular below a input control where data search are performed.
I wanted to post this message to have suggestions for further improvements.
Thanks in advance to all checking in this topic.
Alessandro Rosa
HTML: Select all
function getOBJposition( id, dim )
{
    var obj = document.getElementById( id );
    var top = 0 ;    var left = 0 ;
    
    if ( obj != null || dim.length > 0 )
    {
        dim = dim.toLowerCase();
        while( obj.tagName.length > 0 )
        {
            if ( obj.tagName.toUpperCase() == "BODY" ) break ;
            if ( dim == "top" && obj.tagName != "TR" && obj.tagName != "TBODY" )
            {
                top += obj.offsetTop ;
                top -= obj.clientTop ;
            }
            else if ( dim == "left" && obj.tagName != "TBODY" )
            {
                left += obj.offsetLeft ;
                left -= obj.clientLeft ;
            }
            obj = obj.parentNode ;
        }
        
        if ( dim == "top" ) return top ;
        else if ( dim == "left" ) return left ;
    }
    else
    {
       top = left = width = height = -1 ;
       return false ;
    }
}

Last edited by c010depunkk; Feb 9th, 2008 at 08:34. Reason: please use [HTML] tags when posting HTML
Reply With Quote

Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET Control ViewState Basheer ASP.NET Forum 2 Apr 14th, 2007 10:25
Movieclip Control dazzelworks Flash & Multimedia Forum 3 Oct 30th, 2006 13:11
Background control ahm531 Web Page Design 6 Aug 30th, 2006 14:45
display a image-map grid cell coordinates paokun JavaScript Forum 3 Feb 5th, 2006 17:19


All times are GMT. The time now is 04:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43