【问题标题】:JQuery maphighlight for changing area highlight color based on condition用于根据条件更改区域突出显示颜色的 JQuery maphighlight
【发布时间】:2014-06-06 09:39:03
【问题描述】:

我已经使用地图坐标创建了图像地图,并且必须突出显示坐标,这工作正常,但我需要的是,更改突出显示颜色取决于条件...在第一个条件下突出显示该区域红色然后在第二个条件下,同一区域将用黑色突出显示。我可以突出显示同一区域,但我不能同时更改该区域的颜色。

我在 Fiddle Here 上的示例代码:Fiddle Demo

我尝试过使用

  <script>
        $(document).ready(function () //on page load
        {
            $('area[title*="UPPER"]').each(function ()//get all areas
            {
                $(this).addClass("victory");
            });

            $('area[title*="LOWER"]').each(function ()//get all areas
            {
                $(this).addClass("lose");
            });

            //initialize highlight
            $('.map').maphilight({ strokeWidth: 0, fillColor: "0000FF", fillOpacity: 0.8, singleSelect: true });

            ////map wrap
            $(".victory").click(function () {                
                //This block is what creates highlighting by trigger the "alwaysOn", 
                var data = $(this).data('maphilight') || {};
                data.alwaysOn = !data.alwaysOn;
                $(this).data('maphilight', data).trigger('alwaysOn.maphilight');
                //there is also "neverOn" in the docs, but not sure how to get it to work
            });

            $('.map').maphilight({ strokeWidth: 0, fillColor: "FFFF00", fillOpacity: 0.8});

            $(".lose").click(function () {                
                //This block is what creates highlighting by trigger the "alwaysOn", 
                var data = $(this).data('maphilight') || {};
                data.alwaysOn = !data.alwaysOn;
                $(this).data('maphilight', data).trigger('alwaysOn.maphilight');
                //there is also "neverOn" in the docs, but not sure how to get it to work
            });
        });
    </script>

Fiddle Demo

但这是用第二个填充色覆盖第一个填充色。任何人都可以帮助我解决这个问题。

【问题讨论】:

  • 用相同的坐标覆盖画布...
  • @Mr.Alien 无法获取。你能解释一下吗
  • 查看jsfiddle.net/tZKuv/3,我不会浏览插件文档,但我认为他们可以选择这样做
  • 实际上我需要的是,必须突出显示而不悬停(即始终突出显示)。这在 asp.net 图像映射中可能吗?
  • 是的,我知道了,但我不确定,我是 PHP 开发人员 :)

标签: jquery asp.net map imagemap


【解决方案1】:

您的代码不起作用,因为area.style 没有background-color 属性。另请注意,您没有在小提琴中将titles 设置为areas,而是似乎有alts。

请注意,使用的plug-in 在图像上创建了一个过度的画布元素,并且突出显示颜色是该画布的部分透明部分。如果您想让地图的特定区域变为黄色,则必须更改图像本身,或者使用例如叠加的图像,您可以稍后将其隐藏。

无论如何,使用插件您可以执行以下操作:

$(function () {
    var data = {};
    $('.map').maphilight();
    data.alwaysOn = true;
    data.fillColor = 'ffff00';
    data.fillOpacity = '0.6';
    $('area[alt="UPPER HANOVER TOWNSHIP"]').data('maphilight', data).trigger('alwaysOn.maphilight');
});

A live demo at jsFiddle.

【讨论】:

【解决方案2】:

工作代码如下,检查一下

     $(document).ready(function() //on page load
{
     $('area').each(function()//get all areas
              {
                  var co=$(this).attr('coords');//get coords by attr from area
                  alert(co); //alert coords in alertbox
              });
 });

【讨论】:

  • 您的代码适用于悬停。所以只需删除悬停功能......并且只使用准备好的功能并编写您的代码。 $(document).ready(function() //页面加载 { //你的工作代码在这里 });
猜你喜欢
  • 2011-07-30
  • 2010-12-12
  • 2012-10-24
  • 1970-01-01
  • 2013-02-02
  • 2023-03-19
  • 2011-06-19
  • 2016-03-29
  • 1970-01-01
相关资源
最近更新 更多