Tooltip box

Using the code below am I able to display/hide a tooltip without any
problems, however once the tooltip is displayed its position is fixed
(based on where the mouse first hovered onto the object) and I would
like the tooltip to follow the mouse instead.
What must I change to do this ?

Advertisements

Kim wrote:
> Using the code below am I able to display/hide a tooltip without any
> problems, however once the tooltip is displayed its position is fixed
> (based on where the mouse first hovered onto the object) and I would
> like the tooltip to follow the mouse instead.
> What must I change to do this ?

There are many libraries to do this so why reinvent the wheel? Anyway,
the simplest change I can see:
> var mouse_x = 0;
> var mouse_y = 0;

I advise you to look into the title attribute. Most browsers will
turn it into a tooltip. Furthermore, search engines, screen readers,
text browsers, etc. will be able to see the content. No script
required. That should save you a lot of trouble.

On Nov 4, 10:01 am, Robin <> wrote:
> Kim wrote:
> > Using the code below am I able to display/hide a tooltip without any
> > problems, however once the tooltip is displayed its position is fixed
> > (based on where the mouse first hovered onto the object) and I would
> > like the tooltip to follow the mouse instead.
> > What must I change to do this ?
>
> There are many libraries to do this so why reinvent the wheel? Anyway,
> the simplest change I can see:

Name one that is worthwhile. Wheels should be re-invented when
previous attempts fall short.

If so, that practice is at least not supported by language rules: All
declarations are instantiated *before* execution, so order does not matter.

I found that with languages like this some people declare their functions on
the bottom, presumably so that the main code can be edited easier. I
haven't done that yet, but I see no good reason why I shouldn't. Can you
name one?

No kidding.
>
> I found that with languages like this some people declare their functionson
> the bottom, presumably so that the main code can be edited easier. I
> haven't done that yet, but I see no good reason why I shouldn't. Can you
> name one?

David Mark wrote:
> Thomas 'PointedEars' Lahn wrote:
>> David Mark wrote:
>>> Kim wrote:
>>>> return this;}
>>>> document.onmousemove = getMousePosition;
>>> It is good practice to declare functions before their first use.
>>> [...]
>>>> function getMousePosition(e) {
>> If so, that practice is at least not supported by language rules: All
>> declarations are instantiated *before* execution, so order does not matter.
>
> No kidding.
>
>> I found that with languages like this some people declare their functions on
>> the bottom, presumably so that the main code can be edited easier. I
>> haven't done that yet, but I see no good reason why I shouldn't. Can you
>> name one?
>
> Harder to follow for one.

Why is scrolling down harder to follow than scrolling up?
And with an Outline View the issue gets even smaller. *shrug*

Clearly it isn't. But one can scroll up (or search up or whatever)
knowing that the identifier will be defined above, so it eliminates
the step of looking in the other direction.
> And with an Outline View the issue gets even smaller. *shrug*

[snip]
>
>> Why is scrolling down harder to follow than scrolling up?
> Clearly it isn't. But one can scroll up (or search up or whatever)
> knowing that the identifier will be defined above, so it eliminates
> the step of looking in the other direction.

And if they are at the bottom one can scroll down (or search down or
whatever) knowing that the identifier will be defined below, so it
eliminates the step of looking in the other direction.

Also, down is the default search direction in my editors, I don't have to
change it.

When opening a file the overall top level logic is at the top, ready to
read. If the (hopefully static and never changed much) subroutines are at
the top instead one has to search for the overall top level logic. A PITA if
it is not inside a function itself.

On Nov 4, 8:31 pm, "rf" <> wrote:
> "David Mark" <> wrote in message
>
> news:...
> On Nov 4, 5:30 pm, Thomas 'PointedEars' Lahn <>
> wrote:
>
> [snip]
>
>
>
> >> Why is scrolling down harder to follow than scrolling up?
> > Clearly it isn't. But one can scroll up (or search up or whatever)
> > knowing that the identifier will be defined above, so it eliminates
> > the step of looking in the other direction.
>
> And if they are at the bottom one can scroll down (or search down or

If you put your function declarations after the first use as a rule,
then that should work for you. Seems an odd choice though.

For the record, I know of two scripts that also can do this (+ a lot
more).
1) www.bosrup.com/web/overlib/
2) http://walterzorn.com/tooltip/tooltip_e.htm
I would never use overLIB as it uses incorrect tables (yes, plural) to
create its tooltip. And I am in fact looking into 2) due to its
extension possibilities.
I used an empty div container as it allows me to apply class/styles to
it without having to hardcode it into the JS function or as a
parameter.

David: Im just a novice JS coder, so when the code works then thats
all that matters. If you can provide an example of these changes you
suggest, please do.
The empty link was just for testing. Im using an image instead and I
dont use the title attribute as my text will most likely be longer
than the what it allows (I have seen it cut off text).

David Mark wrote:
> On Nov 4, 10:01 am, Robin <> wrote:
>> Kim wrote:
>>> Using the code below am I able to display/hide a tooltip without any
>>> problems, however once the tooltip is displayed its position is fixed
>>> (based on where the mouse first hovered onto the object) and I would
>>> like the tooltip to follow the mouse instead.
>>> What must I change to do this ?
>> There are many libraries to do this so why reinvent the wheel? Anyway,
>> the simplest change I can see:
>
> Name one that is worthwhile. Wheels should be re-invented when
> previous attempts fall short.

Robin wrote:
> David Mark wrote:
>> On Nov 4, 10:01 am, Robin <> wrote:
>>> Kim wrote:
>>>> Using the code below am I able to display/hide a tooltip without any
>>>> problems, however once the tooltip is displayed its position is fixed
>>>> (based on where the mouse first hovered onto the object) and I would
>>>> like the tooltip to follow the mouse instead.
>>>> What must I change to do this ?
>>> There are many libraries to do this so why reinvent the wheel? Anyway,
>>> the simplest change I can see:
>> Name one that is worthwhile. Wheels should be re-invented when
>> previous attempts fall short.
>
> As Kim says, overLIB (http://www.bosrup.com/web/overlib/)

Have you reviewed the source code? I just did. From the looks of it, it is
just another "library" junk put together by novice script monkeys. Browser
sniffing (they call that "Stupidity Check(tm)", how fitting) and unnecessary
eval() to assemble property access syntax are only some of its problems.

As such, it is easily being recommended by script-kiddies, of course.

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>

On Nov 5, 4:27 am, Robin <> wrote:
> David Mark wrote:
> > On Nov 4, 10:01 am, Robin <> wrote:
> >> Kim wrote:
> >>> Using the code below am I able to display/hide a tooltip without any
> >>> problems, however once the tooltip is displayed its position is fixed
> >>> (based on where the mouse first hovered onto the object) and I would
> >>> like the tooltip to follow the mouse instead.
> >>> What must I change to do this ?
> >> There are many libraries to do this so why reinvent the wheel? Anyway,
> >> the simplest change I can see:
>
> > Name one that is worthwhile. Wheels should be re-invented when
> > previous attempts fall short.
>
> As Kim says, overLIB (http://www.bosrup.com/web/overlib/)

Robin meinte:
> David Mark wrote:
>> On Nov 4, 10:01 am, Robin <> wrote:
>>> Kim wrote:
>>>> Using the code below am I able to display/hide a tooltip without any
>>>> problems, however once the tooltip is displayed its position is fixed
>>>> (based on where the mouse first hovered onto the object) and I would
>>>> like the tooltip to follow the mouse instead.
>>>> What must I change to do this ?
>>> There are many libraries to do this so why reinvent the wheel? Anyway,
>>> the simplest change I can see:
>>
>> Name one that is worthwhile. Wheels should be re-invented when
>> previous attempts fall short.
>
> As Kim says, overLIB (http://www.bosrup.com/web/overlib/)

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!