Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #13206 > unrolled thread

Finding the V offset of an element

Started by"Leonardo Azpurua" <leonardo@exmvps.org>
First post2012-04-03 21:54 -0430
Last post2012-04-07 11:18 -0430
Articles 5 on this page of 25 — 9 participants

Back to article view | Back to comp.lang.javascript


Contents

  Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 21:54 -0430
    Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:18 -0430
      Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-03 22:34 -0430
      Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-04 14:49 +0200
        Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-04 10:28 -0430
          Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:12 +0200
        Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-04 20:28 +0200
          Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:13 +0200
        Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 07:05 -0700
          Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-04 22:28 +0200
            Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 00:44 +0200
              Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 05:50 +0200
                Re: Finding the V offset of an element Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2012-04-05 11:22 +0200
                  Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 13:21 +0200
            Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-05 04:35 -0700
              Re: Finding the V offset of an element Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-04-05 14:02 +0200
                Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-10 09:32 -0700
            Re: Finding the V offset of an element John G Harris <john@nospam.demon.co.uk> - 2012-04-05 14:54 +0100
              Re: Finding the V offset of an element Gene Wirchenko <genew@ocis.net> - 2012-04-05 08:37 -0700
    Re: Finding the V offset of an element Richard Cornford <Richard@litotes.demon.co.uk> - 2012-04-04 04:57 -0700
      Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-05 09:16 +0200
        Re: Finding the V offset of an element "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-04-05 09:38 +0100
          Re: Finding the V offset of an element Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2012-04-08 18:27 +0200
    Re: Finding the V offset of an element Dr J R Stockton <reply1214@merlyn.demon.co.uk.not.invalid> - 2012-04-06 21:52 +0100
      Re: Finding the V offset of an element "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-04-07 11:18 -0430

Page 2 of 2 — ← Prev page 1 [2]


#13233

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2012-04-05 09:16 +0200
Message-ID<9lhqn7t00esaoni3tepmmieshv5k8se165@4ax.com>
In reply to#13215
On Wed, 4 Apr 2012 04:57:56 -0700 (PDT), Richard Cornford wrote:

>There are no reliable general methods (and the ones that get closest
>to being general are quite complex), but given any real-world context
>the odds are that a safe and clean method can be created to do the
>job.

So the following would not work reliably?

function absTop(el) {
  var t = 0;
  do t += el.offsetTop;
  while (el = el.offsetParent);
  return t;
}

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#13235

From"Richard Cornford" <Richard@litotes.demon.co.uk>
Date2012-04-05 09:38 +0100
Message-ID<DPSdnYbaVMh0xODSnZ2dnUVZ8iydnZ2d@giganews.com>
In reply to#13233
Hans-Georg Michna wrote:
> On Wed, 4 Apr 2012 04:57:56 -0700 (PDT), Richard Cornford wrote:
>
>> There are no reliable general methods (and the ones that get
>> closest to being general are quite complex), but given any
>> real-world context the odds are that a safe and clean method
>> can be created to do the job.
>
> So the following would not work reliably?
>
> function absTop(el) {
>  var t = 0;
>  do t += el.offsetTop;
>  while (el = el.offsetParent);
>  return t;
> }

For some values of "reliable", yes. It certainly is not a general 
solution for providing an accurate value for the total pixel offset of 
an element within a displayed document in all contexts. There are other 
factors that this will not take account for. For example; the possible 
non-zero (top/left) border widths of any element within the chain of - 
offsetParent -s. The - offsetTop/Left - is the offset from the inside of 
the containing element to the top/left pixel of the contained element, 
where the inside is within any borders and the top/left pixel is the 
top/left of any border. However, there are contexts where none of the 
elements in the - offsetParent -s chain have borders, padding or 
margins, where that code might be entirely suitable.

Richard. 

[toc] | [prev] | [next] | [standalone]


#13299

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2012-04-08 18:27 +0200
Message-ID<m1f3o7dk2qnrpsdnal9juf7tmkhmuubds6@4ax.com>
In reply to#13235
On Thu, 5 Apr 2012 09:38:04 +0100, Richard Cornford wrote:

>Hans-Georg Michna wrote:

>> On Wed, 4 Apr 2012 04:57:56 -0700 (PDT), Richard Cornford wrote:

>>> There are no reliable general methods (and the ones that get
>>> closest to being general are quite complex), but given any
>>> real-world context the odds are that a safe and clean method
>>> can be created to do the job.

>> So the following would not work reliably?
>>
>> function absTop(el) {
>>  var t = 0;
>>  do t += el.offsetTop;
>>  while (el = el.offsetParent);
>>  return t;
>> }

>For some values of "reliable", yes. It certainly is not a general 
>solution for providing an accurate value for the total pixel offset of 
>an element within a displayed document in all contexts. There are other 
>factors that this will not take account for. For example; the possible 
>non-zero (top/left) border widths of any element within the chain of - 
>offsetParent -s. The - offsetTop/Left - is the offset from the inside of 
>the containing element to the top/left pixel of the contained element, 
>where the inside is within any borders and the top/left pixel is the 
>top/left of any border. However, there are contexts where none of the 
>elements in the - offsetParent -s chain have borders, padding or 
>margins, where that code might be entirely suitable.

Thanks! So does anybody here know of any published routine that
generally solves this problem at least for most not too old
browsers? How about My Library?

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#13273

FromDr J R Stockton <reply1214@merlyn.demon.co.uk.not.invalid>
Date2012-04-06 21:52 +0100
Message-ID<X0BqkKOAe1fPFwvV@invalid.uk.co.demon.merlyn.invalid>
In reply to#13206
In comp.lang.javascript message <jlgbcm$eti$1@dont-email.me>, Tue, 3 Apr
2012 21:54:49, Leonardo Azpurua <leonardo@exmvps.org> posted:

>
>The question is whether there is a safe (and clean, if possible) method to
>find out the absolute position of an element, no matter how deeply nested it
>is.

Asking the user to click on a visible mark in the element, and seeing
what you get, has worked for me.

-- 
 (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk  Turnpike v6.05  MIME.
  Web  <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
  Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
 No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

[toc] | [prev] | [next] | [standalone]


#13291

From"Leonardo Azpurua" <leonardo@exmvps.org>
Date2012-04-07 11:18 -0430
Message-ID<jlpnk9$spv$1@dont-email.me>
In reply to#13273
"Dr J R Stockton" <reply1214@merlyn.demon.co.uk.not.invalid> escribió en el 
mensaje news:X0BqkKOAe1fPFwvV@invalid.uk.co.demon.merlyn.invalid...
> In comp.lang.javascript message <jlgbcm$eti$1@dont-email.me>, Tue, 3 Apr
> 2012 21:54:49, Leonardo Azpurua <leonardo@exmvps.org> posted:
>
>>
>>The question is whether there is a safe (and clean, if possible) method to
>>find out the absolute position of an element, no matter how deeply nested 
>>it
>>is.
>
> Asking the user to click on a visible mark in the element, and seeing
> what you get, has worked for me.

Yup... In fact, the DIV is displayed in response to a click event.

So, the "easy" way was to place it centered on the event coordinates.

Thanks!

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.javascript


csiph-web