【问题标题】:jQuery maphilight using "onclick" methodjQuery maphilight 使用“onclick”方法
【发布时间】:2012-01-05 15:42:42
【问题描述】:

我正在使用 maphilight 插件,它适用于具有“usemap”属性的图像,并在鼠标悬停时勾勒出地图中定义的区域

(此处的文档:http://davidlynch.org/projects/maphilight/docs/)。

我会用 onClick 事件而不是“onmouseover”来触发高亮效果。

我这样做:

jQuery('.area').click(function(e){
    e.preventDefault();

    var data = jQuery(this).mouseout().data('maphilight') || {};
    data.alwaysOn = !data.alwaysOn;
    jQuery(this).data('maphilight', data).trigger('alwaysOn.maphilight');

});

它可以正常工作,但我想在我再次点击时消除高亮效果。

有什么想法吗?

【问题讨论】:

    标签: javascript jquery javascript-events


    【解决方案1】:

    查找这部分代码并更改:

                $(map).trigger('alwaysOn.maphilight').find('area[coords]')
                .bind('mouseover.maphilight', mouseover)
                .bind('mouseout.maphilight', function(e) { clear_canvas(canvas); });
    

    到这里:

                $(map).trigger('alwaysOn.maphilight').find('area[coords]')
                .bind('click.maphilight', mouseover)
                .bind('mouseout.maphilight', function(e) { clear_canvas(canvas); });
    

    将“鼠标悬停”事件更改为“点击”即可。

    【讨论】:

      【解决方案2】:

      查看代码,看起来事件mouseout.maphilight 绑定到将清除画布的高亮图。我猜你可以触发那个事件来清除它。看起来您可能必须自己跟踪状态。

      【讨论】:

        【解决方案3】:
        <code> 
        $('.mianchor').click(function(e) {
                e.preventDefault();
                var colorx = $(this).attr('title');
                var data = {};
                data.alwaysOn = !data.alwaysOn;
                data.stroke = 'none';
                data.strokeWidth = 0.0000001;
                data.strokeColor = colorx;
                data.fillColor = colorx; // Sample color
                data.fillOpacity = 1;
                $('#mapa').data('maphilight', data).trigger('alwaysOn.maphilight');         
            });
        

        【讨论】:

          猜你喜欢
          • 2017-06-19
          • 2012-01-26
          • 1970-01-01
          • 2014-05-10
          • 2016-06-01
          • 2014-01-21
          • 2015-07-10
          • 1970-01-01
          • 2012-11-24
          相关资源
          最近更新 更多