简体   繁体   English

单击并按住图像,而无需将鼠标悬停在其他图像上

[英]Click and hold image without changing the hover into another image

I'm trying to make a regional map in html and javascript, I'm sure how to do the following: 我正在尝试使用html和javascript制作区域地图,我确定如何执行以下操作:

to hover over the city, he should change the city's image with another clearer, and clicking in the city he should get a darker color than the picture when we hover. 若要将鼠标悬停在城市上空,他应使用另一个更清晰的颜色更改城市的图像,然后单击城市时,单击该城市时,他应获得比图片暗的颜色。

Until there all right, but when I click it gets darker image and move the mouse in another city he immediately removes the dark image and return to the clearer picture. 直到一切正常,但是当我单击它时,它会得到较暗的图像,并将鼠标移到另一个城市,他立即删除了较暗的图像并返回到较清晰的图像。

How to keep the image when I click on it and still the effect of passing the mouse? 当我单击它时如何保持图像并仍然具有传递鼠标的效果?

JAVA JAVA

 function mapa_on_1() { document.getElementById("mapaimag").src = "http://IMAGEM_1_click.gif"; } function mapa_over_1() { document.getElementById("mapaimag").src = "http://IMAGEM_1_over.gif"; } function mapa_on_2() { document.getElementById("mapaimag").src = "http://IMAGEM_2_click.gif"; } function mapa_over_2() { document.getElementById("mapaimag").src = "http://IMAGEM_2_over.gif"; } 
 HTML <div id="mapa"> <img border="0" src="http://Caminho_da_IMAGEM_padrao_sem_cor.gif" id="mapaimag" alt="Mapa" width="200" height="200" usemap="#Map" /> <map name="Map" id="Map"> <area href="#" onclick="mapa_on_1();" onMouseover="mapa_over_1();" shape="poly" coords="111,187,113,198,110,174,113,172,110,150,115,161,114,158,118,188,120,155,124,155,132,157,134,156,137,157,139,155,140,157,137" alt="cidade1l" /> <area href="#" onclick="mapa_on_2();" onMouseover="mapa_over_2();" shape="poly" coords="41,96,191,98,147,110,198,109,153,112,157,184,158,117,158,121,144,131,157,132,156,135,177,138,154,129,157,137,158,142" alt="cidade2l" /> 

Please staff, help me, Can anyone give me a hint how to achieve this. 请工作人员,帮助我,任何人都可以给我提示如何实现这一目标。 I see in some code they use (style = "opacity:). but I have no idea if it's used two images of deferent color or not and how to use My Duvia is Keeping the image when I click on it and still the effect of spending mouse? with opacity or not Note: I am new to java 我在某些代码中看到了它们使用的样式(style =“ opacity :)。但是我不知道它是否使用了两种颜色不同的图像,并且如何使用我的Duvia是在单击图像时保持图像的效果,仍然花费鼠标吗?是否具有不透明度注意:我是Java新手

Thank you 谢谢

This is how to use CSS style opacity 这是使用CSS样式不透明度的方法

img {
opacity: 0.4;
filter: alpha(opacity=40); /* For IE8 and earlier */
}

img:hover {
opacity: 1.0;
filter: alpha(opacity=100); /* For IE8 and earlier */
}

opacity by using javascript 使用javascript的不透明度

var element = document.getElementById('id');
element.style.opacity = "0.9";
element.style.filter  = 'alpha(opacity=90)'; // IE fallback

or use like this 或像这样使用

document.getElementById("myDivId").setAttribute("style","opacity:0.5; -moz-opacity:0.5; filter:alpha(opacity=50)");

//-moz-opacity:0.5;  fox mozilla

It works on FireFox, Chrome and IE. 它适用于FireFox,Chrome和IE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM