Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery maphilight using "onclick" method

I'm using maphilight plugin, it applies to images with a 'usemap' attribute, and outlines the areas defined in their map on mouseover.

(documentation here: http://davidlynch.org/projects/maphilight/docs/).

I would to trigger the hilight effect with the onClick event instead of "onmouseover".

I do this:

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');
    
});

It works correctly but I want to erase the hilight effect when I make a new click.

Any ideas?

like image 916
mariobros Avatar asked Aug 28 '26 03:08

mariobros


1 Answers

Look for this part of the code and change:

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

To this:

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

Changing the "mouseover" event to "click" will do the trick.

like image 150
Rafael González Avatar answered Aug 29 '26 16:08

Rafael González



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!