On Dec 7, 10:34 am, doug <[email protected]> wrote:
> From searching and looking at the API docs, doesn't look like
> prototype is able to do this, but I thought I would ask anyway in case
> some one has an idea.
>
> I have a generic form generator library and in the forms generated, I
> need to be able to absolutely position a "help" div next to an image
> of a question mark.
>
> I need this to work in the following cases:
>
> 1. the form is on a page by itself
> 2. the form is in a lightbox (which is absolutely positioned)
> 3. the form is in a scrollable div on a page by itself
> 4. the form is in a scrollable div INSIDE a lightbox (which is also
> scrollable)
>
> Basically, this requires me find a uniform way to get the absolute
> position of the question mark image.
>
> positionedOffset works for 1 and 2. For 4 I have to use
> positionedOffset along with cumulativeScrollOffset and do some math.
> Is there a way to get the absolute position no matter which one of
> these cases?
>
> thanks.
This following function appears to work in every browser we support
except IE7. If the user mouses over obj, it positions the div right
next to obj and displays the html in the div.
function ToolTip(obj, html){
var box = $('toolTipBox'); // id of an absolutely positioned
div
box.innerHTML=html;
box.style.display= "block";
var newObj = obj.parentNode;
var container = box.getOffsetParent(); // page body or lightbox
var scrollTop = 0;
var scrollLeft = 0;
// if in scrollable div, must account for scrolling (IE7
PROBLEMS).
while (newObj && newObj != container) {
scrollTop += newObj.scrollTop;
scrollLeft += newObj.scrollLeft;
newObj = newObj.parentNode;
}
offset = obj.positionedOffset();
var vAdjust = offset['top'] + 2 - scrollTop;
var hAdjust = offset['left'] + obj.getWidth() + 5 - scrollLeft;
box.style.left= hAdjust+"px";
box.style.top= vAdjust+"px";
obj.onmouseout= function(){
box.style.display= "none";
};
}
In IE7, there is no need to account for scrolling if obj is in a
overflow:auto div. In IE7, if I add scrolling in, the positioning is
all screwed up. My question is, I know that people say it's not good
to try to detect what browser the user is using, and adjust javascript
accordingly, but I can't think of another way to do this besides just
detecting IE7 somehow, and skipping that portion of the code.
Any ideas on how I can do this without an IE7 browser detect? If not,
what's the best way to do an IE7 browser detect?
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.