Coder Social home page Coder Social logo

pictarea's Introduction

Pictarea

jQuery plugin to draw HTML Image map areas on a canvas and manage selection


Installation

Pictarea depends on jQuery. To use it, include this in your page :

<script src="jquery.js" type="text/javascript"></script>
<script src="pictarea.js" type="text/javascript"></script>

Usage

For this following HTML:

<img id="map" src="{{ url }}" usemap="#map-mask"/>
<map name="map-mask">
  <area shape="rect" coords="10,10,20,20" alt="description 1" target="1" />
  <area shape="rect" coords="30,30,40,40" alt="description 2" target="2" />
</map>

You can call the plugin like this:

$(function() {
  $('#map').pictarea({
    rescaleOnResize: true
  });
});

The receiver must be an img element with its usemap attribute defined.

To create image maps, we suggest you to use the ImageMap Gimp plugin.


Options

normal {object}

Object of properties which will be apply to the canvas context of the area.

Default: { fillStyle: 'rgba(255,255,255,.4)', strokeStyle: 'rgba(255,255,255,.8)', lineWidth: 1 }

hover {object}

Object of properties which will be apply to the canvas context of the area when hovered.

Default: { fillStyle: 'rgba(255,255,255,.6)', strokeStyle: '#fff', lineWidth: 2, shadowColor: '#fff', shadowBlur: 10 }

active {object}

Object of properties which will be apply to the canvas context of the area when selected.

Default: { fillStyle: 'rgba(255,255,255,.8)', strokeStyle: '#f00', lineWidth: 2 }

disable {object}

Object of properties which will be apply to the canvas context of the area when disabled.

Default: { fillStyle: 'rgba(0,0,0,.4)', strokeStyle: 'transparent' }

areaValueKey {string}

Attribe of the area elements which will be used to fill the value property.

Default: target

areaDisableKey {string}

Attribe of the area elements which will be used to determine if it is disabled.

Default: disabled

maxSelections {number}

Maximum number of selections allowed.

Default: 1

updateOnResize {boolean}

A boolean indicating if the canvas should be redraw when the window is resized.

The window size is checked using requestAnimationFrame for good performance.

Default: false


Event

enterArea.pictarea

This event fires whenever mouseover is trigger on an area.

$img.on('enterArea.pictarea', function(evt) {
  // ex: show a tooltip
  var $area = $(evt.area),
    offset = $img.offset(),
    top = evt.originalEvent.pageY - offset.top,
    left = evt.originalEvent.pageX - offset.left;

  $caption.text($area.attr('alt')).css({ top: top, left: left }).show();
})

leaveArea.pictarea

This event fires whenever mouseout is trigger on an area.

$img.on('leaveArea.pictarea', function(evt) {
  // ex: hide the tooltip
  $caption.hide();
})

selectArea.pictarea

This event fires whenever an area is clicked or touched.

$img.on('selectArea.pictarea', function(evt) {
  // ex: prevent the selection
  evt.preventDefault();
})

change

This event fires whenever the value has changed.

$img.on('change.pictarea', function(evt) {
  var selection = evt.selection,
    value = evt.value;

  // ex: display the value in the console
  console.log(value);
})

Size

Original Size: 3.19KB gzipped (11.68KB uncompressed)

Compiled Size: 1.95KB gzipped (4.75KB uncompressed)


Author

Nicolas Badia


Copyright and license

Copyright 2016-2019 GestiXi under The MIT License (MIT).

pictarea's People

Contributors

nicolasbadia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pictarea's Issues

The plugin only enable when Developer Tools is opened

Hi,
I tried to use this plugin on my image but I can only use it after open the developer tools with Jquery 3.6.0.

If I refresh the page with developer tools opened the plugin dont load.
If I refresh the page and the open the developer tools the plugin load.

Can you help me?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.