473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Control the effect of an onMouseOver function.

I'm attempting to design a site with alot of dynamic content and
intractability, however I've hit a snag when it comes to the function of
the onMouseOver and onMouseOut events. Using a bit of code from
QuirksMode to grab the location of the mouse, I've built a tooltip
function to show a tooltip to the user depicting the target of a link,
the problem is when you mouse over the box that the tooltip function is
attatched to the tooltip flickers... Alot. I attempted to halt the
flickering and movement of the tooltip as the mouse moves across the
link (which is a 15x18 red square) but it seems that even as you move
about in the square, it keeps calling it's MouseOut event.

The following is the JavaScript code in question:

function inittooltip(target)
{
tltp = new getObj(target);
tltp.obj.onmouseover = showtooltip;
tltp.obj.onmouseout = stoptooltip;
}

function showtooltip(e)
{
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

var posx = 0;
var posy = 0;
var targ;

if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}else if (e.clientX || e.clientY)
{
posx = e.clientX;
posy = e.clientY;
if (isIE)
{
posx += document.body.scrollLeft;
posy += document.body.scrollTop;
}
}

if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;

if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug

if (targ == "[object HTMLImageElement]") targ = targ.parentNode;

tltarg = new getObj('tltp' + targ.id);

if (tltarg.style.display != "block")
{
tltarg.style.left = posx + 'px';
tltarg.style.top = (posy - 20) + 'px';
tltarg.style.display = "block";
}
}

function stoptooltip(e)
{
var targ;

if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;

if (targ.nodeType == 3) targ = targ.parentNode;

if (targ == "[object HTMLImageElement]") targ = targ.parentNode;

tltarg = new getObj('tltp' + targ.id);

tltarg.style.display = "none";
}

function getObj(name)
{
if (document.getElementById)
{
this.obj = document.getElementById(name);
this.style = document.getElementById(name).style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}

else if (document.layers)
{
this.obj = getObjNN4(document,name);
this.style = this.obj;
}
}

function getObjNN4(obj,name)
{
var x = obj.layers;
var thereturn;
for (var i=0;i<x.length;i++)
{
if (x[i].id == name)
thereturn = x[i];
else if (x[i].layers.length)
var tmp = getObjNN4(x[i],name);
if (tmp) thereturn = tmp;
}
return thereturn;
}

As you can see, I have the code checking to see if the element is
already being displayed (display != "block"), but when I put an alert
box in to show me what the display value for the element is, I
consistantly get "none".

If anyone knows a way to solve this, or at the least why it is firing
the MouseOut event willy nilly, I would be much obliged.
Feb 21 '06 #1
2 3330
Zif
Justin Rowe wrote:
I'm attempting to design a site with alot of dynamic content and
intractability, however I've hit a snag when it comes to the function of
the onMouseOver and onMouseOut events. Using a bit of code from
QuirksMode to grab the location of the mouse, I've built a tooltip
function to show a tooltip to the user depicting the target of a link,
the problem is when you mouse over the box that the tooltip function is
attatched to the tooltip flickers... Alot. I attempted to halt the
flickering and movement of the tooltip as the mouse moves across the
link (which is a 15x18 red square) but it seems that even as you move
about in the square, it keeps calling it's MouseOut event.


It probably happens because after you display the 'tool tip', if you
move the cursor over the tool tip the anchor element's mouseout fires
and hides the tip. Suddenly the cursor is over the element again, so
the mouseover event fires and shows the tool tip again. Move the cursor
and it happens all over again. It probably happens when you move the
cursor left to right, but not right to left (assuming you put the tool
tip to the right of the cursor).

Have a look here:

<URL:http://www.walterzorn.com/tooltip/tooltip_e.htm>
One solution is don't use the mouseout event of the anchor element to
hide the tool tip. Hide it when you get a mouseover event from an
element that is not: the anchor element, a child of the anchor element,
the tool tip itself or a child of the tool tip.

[...]

--
Zif
Feb 21 '06 #2
Wow. That function works amazingly, however I'd rather not use it,
because I can't figure out for the life of me how it works. I make a
point not to just take something when I don't know how it works (no
good to get dependant on handed out code).

I tried getting the mouseover event of another element to close the
tooltip, however it doesn't seem to work (at least not with my layout).

Here's the revised code (less the object retrieval):
var tltarg;

function inittooltip(target)
{
tltp = new getObj(target);
tltp.obj.mouseover = showtooltip;
stoptltp = new getObj('navbox');
stoptltp.obj.onmouseover = stoptooltip;
}

function showtooltip(e)
{
var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

var posx = 0;
var posy = 0;
var targ;

if (!e) var e = window.event;
if (e.pageX || e.pageY)
{
posx = e.pageX;
posy = e.pageY;
}else if (e.clientX || e.clientY)
{
posx = e.clientX;
posy = e.clientY;
if (isIE)
{
posx += document.body.scrollLeft;
posy += document.body.scrollTop;
}
}

if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;

if (targ.nodeType == 3) targ = targ.parentNode; // defeat Safari bug

if (targ == "[object HTMLImageElement]") targ = targ.parentNode;

tltarg = new getObj('tltp' + targ.id);

if (tltarg.style.display != "block")
{
tltarg.style.left = posx + 'px';
tltarg.style.top = (posy - 20) + 'px';
tltarg.style.display = "block";
}
}

function stoptooltip(e)
{
alert(e.target.id);
tltarg.style.display = "none";
}

And just for clarity, here is the page with the elements being
manipulated:
<div id="mainmenu" style="position: absolute; top: 100px; left:
300px;">
<span id="maintitle" style="z-index: 3;">
<img src="template/images/babilnet_title.jpg" />
</span>
<span id="navbox" style="z-index: 2;">
<span id="about" class="boxlink" onmouseover="inittooltip('about')">
<img src="template/images/babilnet_block.jpg" />
</span>
<span id="products" class="boxlink"
onmouseover="inittooltip('products')">
<img src="template/images/babilnet_block.jpg" />
</span>
<span id="subsidiaries" class="boxlink"
onmouseover="inittooltip('subsidiaries')">
<img src="template/images/babilnet_block.jpg" />
</span>
<span id="portfolio" class="boxlink"
onmouseover="inittooltip('portfolio')">
<img src="template/images/babilnet_block.jpg" />
</span>
<span id="content" class="boxlink"
onmouseover="inittooltip('content')">
<img src="template/images/babilnet_block.jpg" />
</span>
<span id="contact" class="boxlink"
onmouseover="inittooltip('contact')">
<img src="template/images/babilnet_block.jpg" />
</span>
<div id="display" style="z-index: 1;">
</div>
</span>

</div>
<span id="tltpabout" class="tooltip" style="z-index: 10; position:
absolute;">
About
</span>
<span id="tltpproducts" class="tooltip" style="z-index: 10; position:
absolute;">
Products
</span>
<span id="tltpsubsidiaries" class="tooltip" style="z-index: 10;
position: absolute;">
Subsidiaries
</span>
<span id="tltpportfolio" class="tooltip" style="z-index: 10; position:
absolute;">
Portfolio
</span>
<span id="tltpcontent" class="tooltip" style="z-index: 10; position:
absolute;">
Content
</span>
<span id="tltpcontact" class="tooltip" style="z-index: 10; position:
absolute;">
Contact
</span>

This is being pulled into an index.php via a require() function call.

Feb 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
7
by: windandwaves | last post by:
Hi Gurus I am trying to make this rather complicated maps with an a huge number of mouseovers and the like. I want to set up a function that OnMouseDown swaps the OnMouseOver and OnMouseOut for...
13
by: windandwaves | last post by:
Hi Folk Just a bit of help here for newbies who want their menus to look nicer. I am sure that many of you make menus like this <ul id="menu"> <li><a href="page1.html">option 1</a></li>...
6
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
2
by: Bendik Engebretsen | last post by:
I'm an ASP newbie and have just started experimenting with ASP.NET 2.0 using the VS.NET 2005 Beta. As a starting point I have used the 'Personal WEB site' starter kit. I am now trying to figure...
18
by: Luke Skywalker | last post by:
Hi guys, I have to simulate the removing of a file in Windows with Javascript: in other words I drag an image above a layer and the image disappears (like the recycle bin). I know (or better I...
4
by: Amy | last post by:
I need some help. I have this table with alternate row colors. Class gray and class white. I have javascript that do highlight when mouseover row ... and onclick to select row and highlight it...
2
by: AndrewC | last post by:
I am using the Scriptaculous/Prototype libraries to build a project and I really want to have an effect like the mootools download page (http://www.mootools.net/download) where when you mouse over...
0
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Hi, Is it possible to access an htc file from the windows webbrowser control? I am receiving the following error: "An error has occurred in the script on this page." "Error: Access is denied...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.