jquery - 使用 Jquery Maphilight 插件更改单击区域的填充颜色

标签 jquery dictionary highlight

我正在使用 JQuery maphilight 插件来突出显示世界地图中的区域。现在我已经为区域元素设置了以下默认选项

fillColor: 'F25607' //orange color
alwaysOn:  'true'

因此,在页面加载时,区域元素的颜色为橙色。我为每个区域元素都有一个 onclick 事件。 我需要将 map 中单击的区域元素的突出显示颜色(即 fillColor)更改为不同的颜色,例如绿色 当我单击 map 中的另一个元素时,该元素应更改为绿色,而先前选定的元素应更改回橙色。 这是我的 map 的示例代码

<img id="theImg" class="map" src="/gra/images/worldblank.png" usemap="#worldmap" />
<map id="worldmap" name="worldmap">
      <area class='area' shape="circle" alt="Israel" title="Israel" coords="423,232,7" href="#" onclick="loadActivity('Israel');" />
      <area class='area' shape="circle" alt="China" title="China" coords="548,229,5" href="#" onclick="loadActivity('China');"  />
</map>   

要完成的示例 js 函数是:

<script>
jQuery(document).ready(function(){
        jQuery('.map').maphilight();
    });

$(function() {
  $('.area').click(function(e) {
e.preventDefault(); // from the samples, i guess used to overrride default options
// get the clicked area element and set its fillColor to green 
// make the previous selected area fillColor to the default options value  (if we need to do this)
// use the trigger function to trigger this change
    });
 });
</script>

最佳答案

希望这对您有帮助:

<script>
$(function() {
  $('.area').click(function(e) {
    e.preventDefault();
    var data = $(this).data(maphilight) || {};
    data.fillColor = 'FF0000'; // Sample color

    // This sets the new data, and finally checks for areas with alwaysOn set
    $(this).data('maphilight', data).trigger(alwaysOn.maphilight);
  });
});
</script>

来源:Example from the official documentation .

关于jquery - 使用 Jquery Maphilight 插件更改单击区域的填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9541922/

相关文章:

javascript - 如何根据所选的数据列表选项选择复选框(不同页面)

javascript - jplayer 无法在带有多个音频文件的 Chrome 中工作

r - 涉及行特定和整组元素的组特定计算

jquery - 使用绑定(bind)到 DOM 元素的 D3 数据更改 DOM 元素的属性

java - DefaultHighlightPainter 在 JTextPane 中不断移动

javascript - 是否可以将内嵌 javascript 代码插入到另一个 javascript/jquery 代码中?

javascript - IE javascript 兼容性让我很苦恼

python - 为什么 View 对象在 Python Sort() 函数的上下文中是可索引的?

python - 如何通过读取 .txt 文件为每个键创建具有多个 'lists' 的 Python 字典?

html - 如果选中复选框,则突出显示复选框之前的标签