Using AREA Coordinates to create a custom Image Map with Image-Based Rollovers, incorporating jQuery for enhanced functionality if desired

I am looking for a solution similar to this:

http://plugins.jquery.com/project/maphilight

However, instead of just adding a border or fill color to <AREA> tags on rollover, I need them to display a background image. The image should be clipped by the shape of the <AREA>s.

Any suggestions on how to achieve this?

The current setup I have is as follows:

<img usemap="#map" />
<map name="map">
  <area coords="foo,bar">
  <area coords="foo,bar">
  <area coords="foo,bar">
</map>

I would like the background image of each AREA tag to change on rollover.

A demo of what I am envisioning can be seen here:

tankedup-imaging. com/css_dev/rollover.html

However, please note that in this example, it is not a traditional image map and the rollover areas are not truly defined by AREA tags.

Answer №1

It seems that using a traditional image map won't achieve what you're looking for:

<img usemap="#map" />
<map name="map">
    <area coords="foo,bar">
    <area coords="foo,bar">
    <area coords="foo,bar">
</map>

However, there is an alternative method to accomplish your goal using only HTML and CSS, employing a modified version of the CSS sprites technique. You can find a tutorial on how to implement this approach here:

Here's a brief summary of this technique: DEMO Code

Initially, create your base image as usual. Then, generate various hover states by doubling the canvas size of your image and incorporating the hover effect in the new lower section. This will result in something akin to this:

Hopefully, your image looks more appealing than this example. http://demo.raleighbuckner.com/so/1369820/test.jpg

Next, proceed with the HTML and CSS setup using an unordered list:

<style>
    #fakeMap { 
        list-style: none; margin: 0; padding: 0;  
        position: relative;                       
        width: 200px;                             
        height: 100px;                            
        background: url(test.jpg) no-repeat 0 0;      
    }
    #fakeMap li {
        position:absolute; 
    }
    #fakeMap a {
        display:block;       
        width:100%;           
        height:100%;
        text-indent:-5000px;  
    }

    /* Determine each LI's dimensions and position. */
    #maplink1 { width:15px; height:15px; top:10px; left:10px; }
    #maplink2 { width:20px; height:20px; top:30px; left:30px; }
    #maplink3 { width:80px; height:30px; top:20px; left:70px; }

    /* Define the image for all links. */
    #fakeMap a:hover { background: url(test.jpg) no-repeat; }

    /* Specify the background position for each link individually. */
    #fakeMap #maplink1 a:hover { background-position:-10px -110px; }
    #fakeMap #maplink2 a:hover { background-position:-30px -130px; }
    #fakeMap #maplink3 a:hover { background-position:-70px -120px; }
</style>

<ul id="fakeMap">
    <li id="maplink1"><a href="link1.htm">Link 1 Text</a></li>
    <li id="maplink2"><a href="link2.htm">Link 2 Text</a></li>
    <li id="maplink3"><a href="link3.htm">Link 3 Text</a></li>
</ul> 

Answer №2

Alright, here's how I tackled it.

To begin, create an image map as shown below:

<img src="menu.png" id="main-menu" usemap="#imagemap" />              

<map id="imagemap" name="imagemap">
    <area id="option1" href="page1.html" shape="rect" coords="12,33,87,67" />
    <area id="option2" href="page2.html" shape="rect" coords="110,25,156,70" />
</map>

Next, utilize jQuery to change the SRC attribute of the IMG when a user hovers over a specific AREA, and revert back on mouseout.

$(document).ready(function() {

// designate off state 
var menu_off = "/images/menu-off.png";

// functions for hover and revert
function hover(image) {
    $("#main-menu").attr("src", image);
}
function revert() {
    $("#main-menu").attr("src", menu_off);
}

$("#imagemap area").hover(
    function () {
        var selection = $(this).attr("id");
        hover("/images/menu-" + selection + ".png");
    },
    function () {
        revert();
    });

});

This method could potentially be integrated with CSS Sprites to modify the background-position of an image upon rollover.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for transferring information obtained from an API to my custom HTML page

As a novice in web development, I recently created a simple weather report website using the OpenWeather API. While I successfully fetched data from the API, I encountered an issue trying to display this data on my HTML page. Despite utilizing DOM manipu ...

Is it possible to refresh the page without using a hashtag and stay on the same page in AngularJS

Is it possible to refresh my view from the navigation bar without displaying the server folder? I have the html5Mode activated: if(window.history && window.history.pushState) { $locationProvider.html5Mode(true); } ...

Utilize Aframe to easily view and upload local gltf files

I've been working on a project to create a user-friendly panel for loading and viewing gltf models in real-time in A-frame. Here is the current workflow I am following: Using the input tag to load files from local storage. Using v-on-change to assi ...

Utilizing regex patterns within Jqgrid

I am currently utilizing the JqGrid plugin (version 4.6.0 - jQuery Grid) to filter my results using specific fields. Here is an example of how the GUI appears: https://i.sstatic.net/BqGai.png With a large list of employees, I want the ability to filter t ...

Tips for integrating the SlitSlider jQuery plugin into your website

Trying to incorporate the SlitSlider carousel into my project has proven challenging due to a lack of thorough documentation. Has anyone successfully implemented this? I keep encountering the error message: TypeError: self._init is not a function You can ...

Extracting the id of an element using jQuery

The desired outcome is for the code to print the id of the selected div, but it's not working as expected. I've reviewed it multiple times but couldn't pinpoint the error. Any assistance would be greatly appreciated. Here is the HTML: < ...

Learn how to iterate over an array and display items with a specific class when clicked using jQuery

I have an array with values that I want to display one by one on the screen when the background div is clicked. However, I also want each element to fade out when clicked and then a new element to appear. Currently, the elements are being produced but th ...

Encountering the error of receiving "$ undefined," despite making a reference to the library

I have included the JQuery library in the following way: <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script> Despite trying to download the library and include it locally in my project, I ...

CSS failing to accurately calculate width when children have percentage values assigned

This CSS quirk is quite interesting... An inline-block container will correctly calculate width when using units like px, vw, em, etc. But it behaves differently when using a percentage-based measurement. Percentage Example: https://i.sstatic.net/saI0M.j ...

Issue with an Angular filter for formatting a lengthy JSON string onto separate lines within an HTML document

Just starting out with coding and working in Angular, I'm trying to display JSON data from Firebase in HTML. Here's the specific call I'm using: <p>{{workout[0].box.info.training.strength.exercise[1].movement.freetext }}</p> Th ...

Vue: Opening all GmapInfoWindows simultaneously upon clicking one

I am working on a platform where users can report crimes or incidents by placing markers on a map. These markers with all the reported incidents are then displayed on another map. Each marker has an info window that provides details about the incident and ...

Custom toString() method not executed when object is created using object literal syntax

Currently, I am facing an issue with my code. I have a class called Foo which has overridden the default implementation of toString(). class Foo { bar: string; toString(): string { return this.bar; } } Whenever I create a new variable usi ...

Angular is using double quotes (%22) to maintain the integrity of the data retrieved from JSON responses

After running a PHP script, the following response is returned: {"result": "0", "token":"atoken" } To execute the script with Angular, the following code is used: $http.post( API["R001"], $scope.user, {}).then($scope.postSuccess, null); Upon successful ...

Broadcast and listen to events in AngularJS using `$rootScope.$emit`

I am currently working on a large Angular app and I have encountered the need to trigger an event using $rootscope.$emit, and then listen to this event inside a factory. Doing this inside a controller is not feasible because the controller hasn't load ...

Can transitions be applied to links in this manner?

Having an issue with ajax requests, I am currently resorting to using JavaScript linking. This is how I normally link: window.location.href = ('file:///android_asset/www/custom/kontakty.html'); I am curious if it's possible to add a transi ...

obtain the .html file as well as the container

Similar Question: jQuery - Get selected element's outer HTML So, I have a div containing some elements: <div id="fred"> It has certain content inside it: <div id="fred"> <tr id="thing1">hello1</tr> <t ...

Caution: Server Components can only pass plain objects to Client Components

My app allows users to search for care homes on a map and add new ones using a form. During development, everything was working fine. However, in production, the map was not updating to show the newly added care homes. It seemed that the API fetching the ...

How to properly align TableHeader and TableBody contents in a Material-UI table

I am experiencing an issue with a file that is supposed to display a table of data pulled from a database. Although the table does appear, all the data seems to be displayed under the ISSUE NUMBER column, instead of being aligned with their respective col ...

Assist me with Twitter

Seeking assistance with a coding issue related to displaying Twitter posts on a website. I have found a code snippet that accomplishes this: //Scrolling of tweets in the footer $(function () { var tweetVP = $("#footerTweetsViewport"); arrTweetNav ...

I am having trouble comprehending this JavaScript code, could someone provide me with assistance?

Currently delving into the world of JavaScript functions and stumbled upon this code snippet with the following output: Output: "buy 3 bottles of milk" "Hello master, here is your 0 change" function getMilk(money, costPerBottle) { ...