473,728 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(tar get)
{
tltp = new getObj(target);
tltp.obj.onmous eover = showtooltip;
tltp.obj.onmous eout = stoptooltip;
}

function showtooltip(e)
{
var isOpera = (navigator.user Agent.indexOf(' Opera') != -1);
var isIE = (!isOpera && navigator.userA gent.indexOf('M SIE') != -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.s crollLeft;
posy += document.body.s crollTop;
}
}

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 HTMLImageElemen t]") targ = targ.parentNode ;

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

if (tltarg.style.d isplay != "block")
{
tltarg.style.le ft = posx + 'px';
tltarg.style.to p = (posy - 20) + 'px';
tltarg.style.di splay = "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 HTMLImageElemen t]") targ = targ.parentNode ;

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

tltarg.style.di splay = "none";
}

function getObj(name)
{
if (document.getEl ementById)
{
this.obj = document.getEle mentById(name);
this.style = document.getEle mentById(name). style;
}
else if (document.all)
{
this.obj = document.all[name];
this.style = document.all[name].style;
}

else if (document.layer s)
{
this.obj = getObjNN4(docum ent,name);
this.style = this.obj;
}
}

function getObjNN4(obj,n ame)
{
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 3356
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(tar get)
{
tltp = new getObj(target);
tltp.obj.mouseo ver = showtooltip;
stoptltp = new getObj('navbox' );
stoptltp.obj.on mouseover = stoptooltip;
}

function showtooltip(e)
{
var isOpera = (navigator.user Agent.indexOf(' Opera') != -1);
var isIE = (!isOpera && navigator.userA gent.indexOf('M SIE') != -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.s crollLeft;
posy += document.body.s crollTop;
}
}

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 HTMLImageElemen t]") targ = targ.parentNode ;

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

if (tltarg.style.d isplay != "block")
{
tltarg.style.le ft = posx + 'px';
tltarg.style.to p = (posy - 20) + 'px';
tltarg.style.di splay = "block";
}
}

function stoptooltip(e)
{
alert(e.target. id);
tltarg.style.di splay = "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="in ittooltip('abou t')">
<img src="template/images/babilnet_block. jpg" />
</span>
<span id="products" class="boxlink"
onmouseover="in ittooltip('prod ucts')">
<img src="template/images/babilnet_block. jpg" />
</span>
<span id="subsidiarie s" class="boxlink"
onmouseover="in ittooltip('subs idiaries')">
<img src="template/images/babilnet_block. jpg" />
</span>
<span id="portfolio" class="boxlink"
onmouseover="in ittooltip('port folio')">
<img src="template/images/babilnet_block. jpg" />
</span>
<span id="content" class="boxlink"
onmouseover="in ittooltip('cont ent')">
<img src="template/images/babilnet_block. jpg" />
</span>
<span id="contact" class="boxlink"
onmouseover="in ittooltip('cont act')">
<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="tltpproduct s" class="tooltip" style="z-index: 10; position:
absolute;">
Products
</span>
<span id="tltpsubsidi aries" class="tooltip" style="z-index: 10;
position: absolute;">
Subsidiaries
</span>
<span id="tltpportfol io" 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
5778
by: Yuk Cheng | last post by:
<<<start index.htm>>> <html> <head> <script> function perform(action){ } </script> </head>
7
3340
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 the same element. E.g. <A HREF="#" OnMouseOver="A(); return true" OnMouseOut"B(); return true;"
13
4806
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> <li><a href="page2.html">option 2</a></li> <li><a href="page3.html">option 3</a></li>
6
14694
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 using the Imagebutton.Attributes.Add("onMouseOver","this.src = 'somepicture.jpg') and that works fine. I've tried some java script to change the other control's visible property by changing is className, but that doesn't seem to work
2
17756
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 out how to make my image buttons come 'alive' with a mouseover effect. I am used to DHTML and using the mouseover event to change the bitmap. But what is the correct/best way to do this in ASP.NET ? Any experienced ASP.NET people who would care to...
18
1999
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 thought to know) the way to write the script: in effect I'm not able to indicate to browser that the image is above the layer. This is the code (in short):
4
19558
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 with another color. Also created a class called "Selected". You can only select a row at a time. My problem is, if a row is preselected, when mouseover the selected row, the selected color is screwed. Until you click on the selected row once, the...
2
2651
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 the lines at the bottom very fast, the lines do not highlight. They only highlight if your mouse is over them for slightly longer. Sadly, I can't use the mootools library, so I am hoping someone can point me in the right direction. I am...
0
1841
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 to " "Url: about:blank" I am able to access the htc file when i run the host web page as a normal
0
8905
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9278
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9138
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8136
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4524
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3236
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2161
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.