Positioning DIV for Predictive-Test/LOV/Suggest-list

R

Richard Maher

Hi,

The following is what I'm using to work out where to position the
container-div for my bespoke Auto-Complete list: -

var dimTarget = lovTarget;
var offsetTop = dimTarget.offsetTop + dimTarget.offsetHeight;
var offsetLeft = dimTarget.offsetLeft;

while(dimTarget = dimTarget.offsetParent){
offsetTop += dimTarget.offsetTop;
offsetLeft += dimTarget.offsetLeft;
}

targetDiv.style.top = offsetTop + "px";
targetDiv.style.left = offsetLeft + "px";

Seems to work with IE and FF except when FF has "Overflow: Hidden" on the
Body in which case there is a shimmy.

Can someone please tell me what other offsets I need to take into the
equation?

Cheers Richard Maher
 
S

SAM

Le 11/22/09 11:44 AM, Richard Maher a écrit :
Hi,

The following is what I'm using to work out where to position the
container-div for my bespoke Auto-Complete list: -

var dimTarget = lovTarget;
var offsetTop = dimTarget.offsetTop + dimTarget.offsetHeight;
var offsetLeft = dimTarget.offsetLeft;

while(dimTarget = dimTarget.offsetParent){
offsetTop += dimTarget.offsetTop;
offsetLeft += dimTarget.offsetLeft;
}

targetDiv.style.top = offsetTop + "px";
targetDiv.style.left = offsetLeft + "px";

it's almost what it's shown here :
<http://www.quirksmode.org/js/findpos.html>

do {
offsetTop += dimTarget.offsetTop;
offsetLeft += dimTarget.offsetLeft;
} while(dimTarget = dimTarget.offsetParent);
Seems to work with IE and FF except when FF has "Overflow: Hidden" on the
Body in which case there is a shimmy.

isn't it a funny idea to set the body in hidden overflow
while the container of this body (the window) is already in this state
no ?
What is the utility of such a rule ?

Anyway the overflow hidden is a bad idea with Ff at least for printing,
don't forget to realize a print styles sheet overwritten the overflows
(or the sizes of their containers)
Can someone please tell me what other offsets I need to take into the
equation?

<http://www.quirksmode.org/dom/tests/elementdimensions.html>

If overflowing the body is an IE necessity,
make styles for him in an MS conditional comment.
<http://msdn.microsoft.com/en-us/library/ms537509(VS.85).aspx#UsingCCs>
<http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx>

if not only for IE :

body.style.overflow = 'none';
positionateMyObj('lovTarget');
body.style.overflow = '';

no ?

or perhaps

....
var container = dimTarget;
do {
container = container.parentNode;
offsetTop += dimTarget.offsetTop;
offsetLeft += dimTarget.offsetLeft;
} while ( container.parentNode != document.body &&
dimTarget = dimTarget.offsetParent );
....
 
D

David Mark

Hi,

The following is what I'm using to work out where to position the
container-div for my bespoke Auto-Complete list: -

      var dimTarget  = lovTarget;
      var offsetTop  = dimTarget.offsetTop  + dimTarget.offsetHeight;
      var offsetLeft = dimTarget.offsetLeft;

      while(dimTarget = dimTarget.offsetParent){
        offsetTop  += dimTarget.offsetTop;
        offsetLeft += dimTarget.offsetLeft;
      }

      targetDiv.style.top  = offsetTop  + "px";
      targetDiv.style.left = offsetLeft + "px";

Seems to work with IE and FF except when FF has "Overflow: Hidden" on the
Body in which case there is a shimmy.

Never use overflow:hidden on the body. ;)
Can someone please tell me what other offsets I need to take into the
equation?

Hard to say. Depends on your DOM structure, styles, etc. I recommend
leaving borders off the containers so you don't have to deal with
clientLeft/Top.

And the fewer "hops" the better. Make the container for the widget
position:relative. Then you can stop there (you may not even need a
loop). Your suggest DIV should be a child of the container, not the
body.
 
D

David Mark

Le 11/22/09 11:44 AM, Richard Maher a écrit :








it's almost what it's shown here :
<http://www.quirksmode.org/js/findpos.html>

   do {
         offsetTop  += dimTarget.offsetTop;
         offsetLeft += dimTarget.offsetLeft;
       } while(dimTarget = dimTarget.offsetParent);


isn't it a funny idea to set the body in hidden overflow
while the container of this body (the window) is already in this state
  no ?
What is the utility of such a rule ?

The body has nothing to do with the window. The default overflow for
body is typically "visible". The default overflow for the HTML
element is "auto". In _quirks mode_, the HTML element is not rendered
(in most modern browsers), so the body will have "auto" overflow.
Anyway the overflow hidden is a bad idea with Ff at least for printing,
don't forget to realize a print styles sheet overwritten the overflows
(or the sizes of their containers)

It's a bad idea on HTML or BODY in any media.

Dear God no. That site is a shrine to programming by observation.
It's everything that has gone wrong with browser scripting in the last
decade (and likely played no small part in that). Explanations of the
observations betray misconceptions, just like comments in bad
scripts. A good rule is that if the only basis you have is
observational, you have no basis at all. Unfortunately, entire
frameworks have been built (and torn down and rebuilt yearly) by
feeling about. Thanks PPK!
 
R

Richard Maher

Hi SAM, Mark

Thanks for the replies and useful info.

Never use overflow:hidden on the body. ;)

Bit of a long story; the page has two side-by-side divs and I wanted the
whole page to be height: 100% but the right side div to overflow scroll
vertically and hidden horizontally. Sounds easy, but I also appendChild a
div contaning an Applet's object tag and even though it's height and width
are both 0px it still takes up real-estate (IE at least) and those annoying
scroll-bars appear all over the place. In my quest to get rid of them, I
moved from body height: 95%; to body overflow: hidden; to html
overflow:hidden;

It's only now, after removing the body overflow: hidden; that I discover the
html overflow: hidden is doing all I desire. Shimmy gone and no scroll-bars.
The page in question is just an example dealing primarily with connectivity
functionality and the generic LOV code is just to show how easily it can be
achieved (without HTML5 bollocks.) I will not peal back this scab any
further :)

Cheers Richard Maher
 
G

Garrett Smith

That example is broken.

[snip]

Many recent browsers, including Opera, Safari, and Firefox implement
MSIE's element.getBoundingClientRect[1][2] which also included in a w3c
*draft*[3]. getBoundingClientRect is fast and avoids the problems of
differences in offsetTop. offsetTop is a mystery-meat property.

Keep in mind that the CSSOM draft is a *draft*. It has seen significant
changes in offsetTop through the years).

offsetTop is defined by Microsoft using circular logic with the
definition of offsetParent. Looking at MSDN explains why:

offsetTop:
| Retrieves the calculated top position of the object relative to the
| layout or coordinate parent, as specified by the offsetParent
| property.
http://msdn.microsoft.com/en-us/library/ms534303(VS.85).aspx

offsetParent:
| Retrieves a reference to the container object that defines the
| offsetTop and offsetLeft properties of the object.
http://msdn.microsoft.com/en-us/library/ms534302(VS.85).aspx

So we see that offsetTop is taken from the offsetParent, and
offsetParent is the element that defines where offsetTop is taken from.

It's circular logic.

The reader can implement a manual mutual recursion by clicking the links
back and forth. The offsetTop and offsetParent properties are designed
drive a normal human nuts.

Other borwsers copied these properties, but differently. offsetTop and
offsetParent are a mess. You can use them in some cases, but you will
experience differences when measuring in or through TABLE, TD, TR, or
BODY. offsetParent's border width is not generally included in the
offsetTop measurement, so you will need to add in any borders that are
measured through the offsetParent chain.

An older version of CSSOM defined that and that was implemented in Opera
and maybe others (mac IE?).

Dear God no. That site is a shrine to programming by observation.

Yeah, I do see wrong advice on quirksmode when I check it from time to
time. I didn't look in depth at that page, but the findpos.html page is
not a solution that will provide consistent results in other contexts.
It works in only a few cases, and works on that page.

However, some of PPK observations I totally agree with. Like this:

| In my opinion W3C has made some serious mistakes in defining button.
http://www.quirksmode.org/js/events_properties.html#button

The w3c, as usual, went and standardized[4] IE4's event.button[5], but
gave it number values that sort of matched the NS4 "event.which" numbers.

There are several problems with the w3c design:
1) creates a feature that behaves differently an existing IE feature
that already had the same name.
2) does not allow for detecting multiple buttons/combinations
3) does not provide information for no button depressed.

That API is total shit and PPK knows that.

The other problem with that API is that it misfortunately ties "mouse"
to that hardware. The user may be using a writing table or joystick (not
a mouse). The w3c goes as far as using "left" and "right" to define the
way the hardware is designed and configured, while simultaneously
admitting this mistake my mentioning reconfiguration. To say "left"
means "right" is just nonsense, but the w3c provides such provision:

| For mice configured for left handed use in which the button actions
| are reversed the values are instead read from right to left.

Instead, the w3c should have used a new property, say
"event.mouseButton". It should have used terms to describe "default
button", "wheel button", and "context button", and not "left", "middle",
and "right".
</thread-hijack>

[1]http://msdn.microsoft.com/en-us/library/ms536433(VS.85).aspx
[2]https://developer.mozilla.org/en/dom/element.getboundingclientrec
[3]http://www.w3.org/TR/cssom-view/

[4]http://www.w3.org/TR/DOM-Level-2-Events/events.html
[5]http://msdn.microsoft.com/en-us/library/ms533544(VS.85).aspx
 
G

Garrett Smith

Garrett said:
[snip]
The w3c, as usual, went and standardized[4] IE4's event.button[5], but
gave it number values that sort of matched the NS4 "event.which" numbers.
Correction, it did not "sort of match" NS4 "event.which" other than the
fact that there are only three possible values.
 
D

David Mark

That example is broken.

No shock there. Even if it wasn't broken, it's likely another time
capsule of outdated and baseless observations.
[snip]

Many recent browsers, including Opera, Safari, and Firefox implement
MSIE's element.getBoundingClientRect[1][2] which also included in a w3c
*draft*[3]. getBoundingClientRect is fast and avoids the problems of
differences in offsetTop. offsetTop is a mystery-meat property.

Apples and oranges as far as this example goes (and most others as you
virtually never need to measure to the origin). You put a text INPUT
and a div in a relatively positioned container and you can bet their
offsetLeft/Top properties will have a very simple (and calculable)
relationship.

Feature testing for this kind of stuff is also simple. Set an inline
left/top style and note the change in the offsetLeft/Top, correcting
as necessary.

That strategy works in virtually every browser known to man. The gBCR
method is known to work in the very latest browsers, but is not the
right tool for this job anyway.
 
S

SAM

Le 11/22/09 2:32 PM, David Mark a écrit :
The body has nothing to do with the window.

Once again I misspoke ?
I spoke of the browser's window.
(the browser's window is where the web file is displayed)
(by JS you can (you could?) suppress its scrollbars)
Of course that window seems to be by default in overflow auto and not
hidden as I wrote.
The default overflow for body is typically "visible".
The default overflow for the HTML element is "auto".
In _quirks mode_, the HTML element is not rendered
(in most modern browsers), so the body will have "auto" overflow.

Tried in my "modern browsers" (Firefox.3, Safari.4) the quirks-or-not
mode give same results :
overflowing hidden the html --> no more scrollbars.
Alone my IE (6 I think) follows what you say.
It's a bad idea on HTML or BODY in any media.

In Fx it's a bad idea for any element (if printing).
Not sure with other ones.
Dear God no. That site is a shrine to programming by observation.

Yes for part.
[...] A good rule is that if the only basis you have is
observational, you have no basis at all.

What other basis we have to get in regard with personal conception of
css rendering of that MS's browser ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,083
Messages
2,570,591
Members
47,212
Latest member
RobynWiley

Latest Threads

Top