Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2013, 04:28 PM   PM User | #1
Chrys
New Coder

 
Join Date: Aug 2011
Posts: 43
Thanks: 12
Thanked 0 Times in 0 Posts
Chrys is an unknown quantity at this point
pop-up on image map acting weird

I have an image map that I have a separate tool-tip for each poly area. I have a script that pops up a seperate divide for each area at the position of the mouse. The script pops up the tool-tip mostly but it doesn't hide it on mouse-out as I had hoped. If anyone has some thoughts that would point me in the right direction it would be most appreciated!

I know I have ALOT of code here but I am just not sure where the problem is so I put as much as I could.

JavaScript:
Code:
function pw() 
	{return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
	}; 
function mouseX(evt) 
	{return evt.clientX ? evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) : evt.pageX;
	} 
function mouseY(evt) 
	{return evt.clientY ? evt.clientY + (document.documentElement.scrollTop || document.body.scrollTop) : evt.pageY
	}
function popUp(evt,oi) 
	{if (document.getElementById) 
		{var wp = pw(); dm = document.getElementById(oi); ds = dm.style; st = ds.visibility; 
			if (dm.offsetWidth) ew = dm.offsetWidth; 
			else if (dm.clip.width) ew = dm.clip.width; if (st == "visible" || st == "show") { ds.visibility = "hidden"; } 
			else 
			{tv = mouseY(evt) + 20; lv = mouseX(evt) - (ew/4); 
				if (lv < 2) lv = 2; 
				else if (lv + ew > wp) lv -= ew/2; lv += 'px';tv += 'px';  ds.left = lv; ds.top = tv; ds.visibility = "visible";
			}
		}
	}

function original() {
document.usa_map.src = usa.src;
document.getElementByClassName('tip').style.visibility = 'hidden';
return true;
}

function al_switch() {
document.usa_map.src = al.src;
popUp(event,'tt_al');
return true;

function ga_switch() {
document.usa_map.src = al.src;
popUp(event,'tt_coming_soon');
return true;
}
CSS:
Code:
.tip {
position:absolute;
z-index:100;
visibility:hidden;
top:50px;
left:50px;
}
HTML: (separate divide for each tool-tip)
Code:
<area shape="poly" alt="Alabama" coords="662,385,706,380,726,444" onMouseOver="al_switch()" onMouseOut="original()"/>

<area shape="poly" alt="Georgia" coords="797,468,788,467" href="georgia.html" onMouseOver="ga_switch()" onMouseOut="original()"/>

<div id="tt_coming_soon" class="tip">Courses will be available in this state soon!</div>
<div id="tt_al" class="tip">Available in Alabama:<br/>Continuing Education Courses</div>
Chrys is offline   Reply With Quote
Old 01-20-2013, 04:58 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,399
Thanks: 18
Thanked 352 Times in 351 Posts
sunfighter is on a distinguished road
Normally tooltips are controlled via css hover. And I wouldn't use visibility, because it does claim the space it uses in the html. Use display none and inline.
sunfighter is offline   Reply With Quote
Old 01-20-2013, 05:03 PM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Quote:
Originally Posted by Chrys View Post
Code:
function original() {
document.usa_map.src = usa.src;
document.getElementByClassName('tip').style.visibility = 'hidden';
return true;
}
You could start by using the error console, which should tell you that document.getElementByClassName is not a function (nor can it be).
Logic Ali is offline   Reply With Quote
Old 01-20-2013, 10:33 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
Originally Posted by sunfighter View Post
And I wouldn't use visibility, because it does claim the space it uses in the html. Use display none and inline.
Doesn't matter.

Look at the class:
Code:
.tip {
    position:absolute;
    ...
Anything positioned absolute won't affect the positioning of other elements.

I happen to agree with you: I always use display instead of visibility for stuff like this. But in practice it doesn't matter.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
image map, javascript, tooltip

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:28 AM.


Advertisement
Log in to turn off these ads.