How can I select only certain areas of the image?

I have an image of a human skeleton with about 60 areas that I want to select and make clickable. They are in a circle and numbered from 1-60.

The whole idea is that I want to click on the nubmers (on the image) and select this part of the image.

I used jQuery to freeze numbers / areas and highlight (hover over the mouse), and when the user clicks on the number, I get the click number and process the server code. (.NET C #)

But I want the place where I click to remain color ... Pointing to a number and changing the color works fine ... But I want, when it clicks, the color should change on the image / saved ...

Below are samples that change color when you hover over the mouse, but when you click a color, it does not change.

http://davidlynch.org/js/maphilight/docs/

http://davidlynch.org/js/maphilight/docs/demo_simple.html

any ideas how to highlight some areas of the image?

sample code below:

<img class="map" src="Images/Figure_Human_Image1.png" alt="" usemap="#Skeleton17" / > <map name="Skeleton17" > <area title="1" alt="1" href="#" shape="circle" coords="13,174,7" / > <area title="2" alt="2" href="#" shape="circle" coords="27,159,7" / > 

How to PERMANENT highlight on the image

+6
source share
3 answers

Responses to replacing images will work. However, by doing this in images, you end up using more bandwidth than you really need to use for this. One of two things will happen: either people upload a bunch of images that they never upload, or they will have to wait to upload a new image every time they click. For users with a high-speed connection, this will not be a problem, but there is a certain opportunity for users of slow connections (or, possibly, mobile devices) to perceive this as negative.

It would be better to have only one version of the image, which looks like on the first boot. The trick is to make the numbers in the image transparent. Then you can simply change the browser to the background color when clicked. And as a bonus, if you ever want to add other colors to indicate other things, it's easy! And you can select any combination of numbers.

After some experimentation, I found that the style attribute on <area> cannot be used to set the background colors, so you need something else to enforce the colors. I suggest <div> located in the same place as each circle, through something like: <div id='div1' style='position:relative; top:-400px; left:5px; height:30px; width:30px; z-index:-1'>&nbsp;</div> <div id='div1' style='position:relative; top:-400px; left:5px; height:30px; width:30px; z-index:-1'>&nbsp;</div> <div id='div1' style='position:relative; top:-400px; left:5px; height:30px; width:30px; z-index:-1'>&nbsp;</div> where you have to adjust the upper / left values ​​to put them where you need it. z-index:-1 it is important that it is displayed behind the image. To experiment with the placement of these divs, you can go ahead and set the background color to something so that you can see them.

Once you have a transparent image and you have all the divs selected, you just need a little jQuery to activate it. Something like that:

 $('area').click(function(){ var number = $(this).attr('title'); $('#div'+number).css('background-color', 'red'); }) 
+3
source

As Greg B suggested, you can create skeleton images by simply changing the highlighted number, for example:

 Images/Figure_Human_Image1.png : this is your original image with no highlight Images/Figure_Human_Image1_h1.png : this is the skeleton image with number 1 highlighted Images/Figure_Human_Image1_h2.png : this is the skeleton image with number 2 highlighted and so on... 

Then you use jquery to switch the image source with the selected image selected. If the user clicked on number 1, than you replaced src with the image "Images / Figure_Human_Image1_h1.png"

You can do this by adding a click event to area via jquery. In your case, the title attribute of the tag area corresponds to the number of clicks, so it would be something like this:

 $('area').click(function(){ var number = $(this).attr('title'); $('img').attr('src','Images/Figure_Human_Image1_h'+number+'.png'); }) 
+1
source

I do not think you need server side code.

You can create 60 images of various highlighted skeletons, and then using JavaScript, switch the image source with the image with the correct highlighted color

0
source

Source: https://habr.com/ru/post/894707/


All Articles