简体   繁体   English

jQuery / Imagemap组合无法正常工作

[英]Jquery / imagemap combination not working properly

I'm using a combination of Jquery and html imagemap to have a banner with rollovers over different areas. 我使用的是Jquery和html imagemap的组合,以使横幅具有在不同区域的翻转。 The basic function of it works fine, but I've been having issues with making it more advanced. 它的基本功能运行良好,但是在使它更高级方面一直存在问题。

This is the jsfiddle http://jsfiddle.net/2fav4/ 这是jsfiddle http://jsfiddle.net/2fav4/

What's happening, is the hover works fine, the new image appears and all that. 发生的事情是,悬停功能正常,新的图像出现了。 When the user clicks on the image, it stays up (like it's supposed to), the problem is that the clicked state never goes away. 当用户单击图像时,图像会停留(如预期的那样),问题在于单击状态永远不会消失。 I want the user to be able to dismiss the image by clicking it a second time. 我希望用户能够通过再次单击来消除图像。

The trick is to use .toggleClass() . 诀窍是使用.toggleClass()

Simplifying significantly, I get: 大大简化后,我得到:

jQuery("#map-container area").mouseover(function() {
    jQuery('.'+$(this).attr('id')+'-map').show();
}).mouseout(function() {
    jQuery('.'+$(this).attr('id')+'-map').not('.selected').hide();
}).click(function(){
    var regionMap = jQuery('.'+$(this).attr('id')+'-map');
    jQuery('#map-container img.region').not(regionMap).removeClass('selected').hide();
    regionMap.toggleClass('selected').not('.selected').hide();
});

See fiddle 小提琴

You will see that I removed everything to do with ....list as it's non-functional, at least in the HTML I can see. 您会看到,我删除了与....list所有内容,因为它不起作用,至少在我可以看到的HTML中。 If list stuff is important, you will have to add it back in. 如果列表中的内容很重要,则必须重新添加。

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

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