473,401 Members | 2,127 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,401 software developers and data experts.

mouseover only works correctly on second mouseover.

This javascript issue is in an app using C# / .Net 2.0 running on XP.
First post, please mention if I mess up any conventions of this forum.

I’ve got a mouseover event that only works properly the second time it fires if the page has been scrolled a lot. The mouseover displays an image in a div that is placed near the mouse cursor. When the rollover occurs near the bottom of the page, the coordinates are altered so that the entire image is visible – instead of the default location with the top of the image next to the cursor.
This works fine until the user scrolls down. Then, on the mouseover the image appears in its default location even if the cursor is near the bottom of the page so the image is cut off. If you move the cursor off of the location and then back over it, it works correctly.
I output the coordinates of the image and can see that it isn't corrected the first time around, but is the second. It seems to be failing on the line below. This is what determines whether to reset the style.pixelTop of the image.

Thanks in advance, Dave R.

Expand|Select|Wrap|Line Numbers
  1. if (tooltip.style.pixelTop + tooltip.offsetHeight > fullHeight) 
  2.  
  3. Here is all of the relevant code.
  4. ...
  5.     var tooltip = null;
  6.     var txtDisplay = new String();
  7.     var strImgPath = inData;
  8.  
  9.     txtDisplay += "<table><tr><td valign=top>";
  10.     txtDisplay += "<br /><br /><img border=1 src='" + strImgPath + "' /><br /><br />";
  11.     txtDisplay += "</td></tr></table>";    
  12.  
  13.     // IE only
  14.     if (!(document.layers && !document.getElementById)) 
  15.     {
  16.  
  17.         if (document.all) 
  18.         {
  19.             tooltip = document.all.TooltipDIV;
  20.  
  21.             if (!tooltip) 
  22.             {
  23.                 return;
  24.             }
  25.  
  26.             // get position values
  27.             var mouseX = inEvent.clientX;
  28.             var mouseY = inEvent.clientY;
  29.             var fullWidth = document.body.scrollLeft + document.body.offsetWidth - 10;
  30.             var fullHeight = document.body.scrollTop + document.body.offsetHeight - 10;
  31.  
  32.             tooltip.innerHTML = txtDisplay;
  33.  
  34.                 tooltip.style.left = document.body.scrollLeft + mouseX + 20;
  35.             tooltip.style.top = document.body.scrollTop + mouseY - 50; 
  36.  
  37.             tooltip.style.display = "block";
  38.             tooltip.style.visibility = "visible";
  39.             tooltip.style.position = "absolute";
  40.  
  41.             if (tooltip.style.pixelTop + tooltip.offsetHeight > fullHeight) 
  42.             {
  43.                 tooltip.style.pixelTop = (document.body.scrollTop + document.body.offsetHeight) - tooltip.offsetHeight - 10;
  44.             }
  45.  
  46.         }
  47.  
  48. ...
  49.  
Dec 13 '07 #1
1 1933
acoder
16,027 Expert Mod 8TB
Welcome to TSDN!

Perhaps you could try:
Expand|Select|Wrap|Line Numbers
  1. if ((tooltip.style.pixelTop + tooltip.offsetHeight) > fullHeight)
Dec 14 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: richk | last post by:
For some reason when I add additional buttons a 3rd button and beyond i cant get the effect to work and I get errors...I cant understand why... <SCRIPT LANGUAGE = "javascript"><!-- if...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
2
by: Mitch | last post by:
I am hosting a web browser ctl in a container that implements the IDocHostUIHandler interface. I'm using this to control the context menu.This works fine. Then, I added a mouseover event to the...
5
by: JB | last post by:
I am struggling to figure out a way to allow one element to be dragged, but still capture 'mouseover' events on other elements. I've created a simple example to demonstrate what I mean:...
1
by: giloosh | last post by:
Hello All, How can you continue the mouseover event while the mouse is still over an object? For example: I put my mouse over a hyperlink and that triggers an object to move 10px to the right....
3
by: Annette Acquaire | last post by:
I have and image map with a dozen hotspot links on it that I'm trying to get to open a new image over existing one on mouseover of each COORD. The only thing I was able to do was swap image on...
23
by: Schannah | last post by:
I'm trying to create a design which mimics the Radiohead website in the action on this page, but the problem is that they use PHP for the effect and I have no idea about PHP. I'm very amateur: fairly...
10
by: jjamjatra | last post by:
I am struggling with a event model handling problem in Javascript that shows up only in Firefox. I have 2 little websites I'd like you to take a look at: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.