onClick SVG Map背景颜色应仅对父级有效

时间:2018-06-06 18:17:34

标签: javascript jquery

我正在使用SVG Map for India,它工作正常,但问题是 如果我点击任何其他状态,我需要,父ID不会停用 父ID应该与“填充颜色 - 灰色”和子颜色相反 应该活跃在绿色。

附图供参考,请参阅。

SVG India Map

我在Jquery代码下面使用background:

 <script>
  $(document).ready(function(e) {
    $('path[id^="map_"]').click(function(){
      $(this).css('fill', "green");
    });
  });
 </script>

http://www.acmearchitectural.com/indiamapsvgfiles/map.html#

1 个答案:

答案 0 :(得分:0)

我首先要停用所有状态,然后在目标上使用fill

<script>
    $(document).ready(function(e) {
        $('path[id^="map_"]').click(function(){
            var t = $(this)
                th;

            $('path[id^="map_"]').each(function () {
                th = $(this);
                if (th.attr("id") !== t.attr("id")) {
                    th.css('fill', 'gray');
                } else {
                    t.css('fill', "green");
                }
            });
        });
    });
</script>