School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,027 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,217 people online right now. Registration is fast and FREE... Join Now!




Using JS With Image Maps

 
Reply to this topicStart new topic

> Using JS With Image Maps, Creating dynamic image maps.

kewlkreator
Group Icon



post 1 Aug, 2009 - 08:39 AM
Post #1


Image Maps w/ JavaScript
Please note that this tutorial requires basic knowlege of HTML and JavaScript

In this tutorial, we'll create an image map of our solar system. When the viewer hovers over a planet, the paragraph at the bottom will read a description.

Start with our layout.
CODE
<html>
<head>
<title>Image Map</title>
<script>
// Code
</script>
<body>
<img src="solarsys.gif" usemap="#planets" />
<map name="planets">
<area shape="rect" coords="0,0,82,126" href="sun.html"  />
<area shape="circle" coords="90,58,3" href="mercury.html" />
<area shape="circle" coords="124,58,8" href="venus.html" />
</map>
<p id="description"></p>
</body>
</html>


This creates our template. Now, we need a function that writes text to the description box. We'll use:
CODE
function writeDesc(text) {
var box = document.getElementById(description);
box.innerHTML=text;
}


Now since we want users to hover over planets, we'll call the function with a onMouseOver event.
CODE
<area shape ="circle" coords ="90,58,3" onMouseOver="writeDesc('Mercury')" href="mercury.html" />


All together:
CODE
<html>
<head>
<title>Image Map</title>
<script>
function writeDesc(text) {
var box = document.getElementById(description);
box.innerHTML=text;
}
</script>
<body>
<img src="solarsys.gif" usemap="#planets" />
<map name="planets">
<area shape="rect" coords="0,0,82,126" href="sun.html" onMouseOver="writeDesc('Sun')" />
<area shape="circle" coords="90,58,3" href="mercury.html" onMouseOver="writeDesc('Mercury')" />
<area shape="circle" coords="124,58,8" href="venus.html" onMouseOver="writeDesc('Venus')" />
</map>
<p id="description"></p>
</body>
</html>
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!

firebolt
Group Icon



post 2 Aug, 2009 - 04:11 AM
Post #2
This would do better with a little more explanation, especially on why you have chosen this method, rather than another.
Go to the top of the page
+Quote Post

kewlkreator
Group Icon



post 2 Aug, 2009 - 04:20 AM
Post #3
QUOTE(firebolt @ 2 Aug, 2009 - 04:11 AM) *

This would do better with a little more explanation, especially on why you have chosen this method, rather than another.

Thank you. What other methods are there though? This is the only one I know of.
Go to the top of the page
+Quote Post

gregwhitworth
Group Icon



post 7 Aug, 2009 - 08:41 PM
Post #4
QUOTE
Thank you. What other methods are there though? This is the only one I know of.


Flash could easily be used for such a project, and I HATE and LOATH image maps. Talk about cluttering and messing with your code. But, they do have their place, granted most developers don't give it credence any longer - but it still exists.

I think the most important aspect of this is to show a working example, the code is there and that would make it easier for the user to know whether they even need to use this strategy. Good work though kewl.

--

Greg
Go to the top of the page
+Quote Post

kewlkreator
Group Icon



post 8 Aug, 2009 - 04:31 AM
Post #5
Thanks Greg! Sorry, I don't know any Flash. And yes, image maps are on the brink. But they can still be handy! smile.gif
Go to the top of the page
+Quote Post


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/21/09 08:19AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month