AndreaPlanet.com - My door always open to you * Login   * Register * FAQ    * Search
It is currently Mon Sep 06, 2010 10:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Help with javascript tweak?
PostPosted: Sun Jan 18, 2009 10:56 pm 
Offline
Fan

Joined: Sun Jan 18, 2009 10:40 pm
Posts: 4
Code:
HEAD:
<script language="javascript">
function U(F, Coords)
{
   var Z = document.getElementById("MyZoom");
   
   Z.src =  F ;
   Z.style.display = '';
   var C = Coords;
   
   var Top    = C.substr(C.indexOf(",")+1, C.length);   
   var Right  = Top.substr(Top.indexOf(",")+1, Top.length);

   var Left   = C.substring(0, C.indexOf(","));
   var Top    = Top.substring(0, Top.indexOf(","));
   var Right  = Right.substring(0, Right.indexOf(","));   
   var Bottom = C.substr(C.lastIndexOf(",")+1, C.length);
   
   Z.style.left = Right;
   Z.style.top  = Bottom;
}

</script>

BODY:
<img style="position: absolute; left: 0px; top: 0px; width: 300px; height: 225px; border: 1px solid black; display: none" id= "MyZoom" src="" height="128" width="128" />
<img src="Mosaic.jpg" border=0 width=280 usemap="#Map">
<map name="Map">
  <area onmouseover="U(this.href, this.coords);" shape="rect" coords="0,0,17,13" href="A.jpg" target="_blank">
  <area onmouseover="U(this.href, this.coords);" shape="rect" coords="17,0,35,13" href="B.jpg" target="_blank">
  <area onmouseover="U(this.href, this.coords);" shape="rect" coords="35,0,53,13" href="C.JPG" target="_blank">
....
</map>


I know this has got to be simple, how do you get the popped up image to disappear when it leaves the main image or if you click outside the main image?
Would it be something with onmouseout?


Top
 Profile E-mail  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Mon Jan 19, 2009 12:35 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 939
Location: Italy
Abbey wrote:
I know this has got to be simple, how do you get the popped up image to disappear when it leaves the main image or if you click outside the main image?
Would it be something with onmouseout?


I'm not an expert with Javascript, probably on that event I would set the source image to blank (call U("",this.coords) on onmouseout)


Top
 Profile  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Mon Jan 19, 2009 4:11 am 
Offline
Fan

Joined: Sun Jan 18, 2009 10:40 pm
Posts: 4
That didn't work...I sorta got it working, I took out all the mouseovers in the area tags and had the javascript create them dynamically...

Code:
function init () {
var Map = document.getElementsByTagName('area');

for (var i=0l i<Map.length; i++) {
  Map[i].onmouseover = function () {
    U(this.href, this.coords);
  }

  Map[i].onmouseout = function () {
   document.getElementById('MyZoom').style.display = 'none';
  }
}

}

window.onload = init;



though now this part:

Code:
Z.style.display = '';

Stopped working, so I tried:

Code:
Z.style.display = 'block';


and that started working, but the pop-up images where off...


Top
 Profile E-mail  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Mon Jan 19, 2009 4:24 am 
Offline
Fan

Joined: Sun Jan 18, 2009 10:40 pm
Posts: 4
Okay, I take that back, apparently the imagemap can't be surrounded by other div tags... it worked fine all by itself on a plain html page... now I just have a CSS problem with positioning I guess... :?


Top
 Profile E-mail  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Mon Jan 19, 2009 5:33 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 939
Location: Italy
Let me know when you get a solution :)


Top
 Profile  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Tue Jan 20, 2009 3:18 am 
Offline
Fan

Joined: Sun Jan 18, 2009 10:40 pm
Posts: 4
Well, I know what the problem is now. :D

Though, I do not know how to fix it. :(

The problem is the offset... when you have the imagemap inside a div with padding/margin, the U function is off a bit...

So after the
Code:
   Z.style.left = Right;
   Z.style.top  = Bottom;


part I tried to fix the offset with
Code:
   Z.style.marginLeft = 25+'px';
   Z.style.marginTop = 50+'px';   


which was close, but not exactly right for my image.

I'm only intermediate-ish with javascript.

I found 2 people who came with solutions for this problem, but I don't know how to modify the U function to account for offsets.

javascript image map written by Emil Nikolov (GNU General Public License)
http://javascripthowtos.blogspot.com/2008/08/javascript-image-map.html

Javascript image magnifier
http://javascripthowtos.blogspot.com/2008/08/javascript-image-magnifier.html

Imagemap rollover written by Gabriel Svennerberg
http://www.svennerberg.com/2008/09/imagemap-rollover/

If any javascript gurus are out...please help if you can!


Top
 Profile E-mail  
 
 Post subject: Re: Help with javascript tweak?
PostPosted: Sun Jan 25, 2009 9:27 am 
Offline
Site Admin
User avatar

Joined: Mon Apr 15, 2002 9:12 am
Posts: 939
Location: Italy
What about using visibility property?

Code:
function U(F, Coords)
{
   var Z = document.getElementById("MyZoom");
   Z.src =  F ;
   Z.style.display = '';
   Z.style.visibility = "visible";
....
}

function V(I)
{
   var X = document.getElementById("MyZoom");
   X.src =  I ;
   X.style.display = '';
   X.style.visibility = "hidden";
}


And in the map something like this:

Code:
<area onmouseover="U(this.href, this.coords);" onmouseout="V('this,href');" shape="rect" coords="28,0,57,20"  href="images/xxx.jpg" caption="xxxx">


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group