Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yisibell/img-map-area

A library that makes Image Map Area responsive.
https://github.com/yisibell/img-map-area

area image-map-area img img-map-area map map-area responsive responsive-image-map-area

Last synced: 2 months ago
JSON representation

A library that makes Image Map Area responsive.

Awesome Lists containing this project

README

        










# img-map-area

A library that makes Image Map Area responsive.

- [Release Notes](./CHANGELOG.md).

# Features

- One function to make **map area** responsive.
- Support Typescript.

# Installation

```bash
# yarn
$ yarn add img-map-area

# npm
$ npm i img-map-area

# pnpm
$ pnpm add img-map-area
```

# Usage

## Example

handling the **img map area** in the whole page:

```js
// src/plugins/responsive-img-map-area.js

import { responsiveImgMapArea } from 'img-map-area'

window.addEventListener('load', () => {
// Put .map-area-img selector in the element which will be responsive
const elements = document.querySelectorAll('.map-area-img')

const resizeHandler = () => {
elements.forEach((imgEl) => {
responsiveImgMapArea(imgEl)
})
}

resizeHandler()

window.addEventListener('resize', resizeHandler)
})
```

> Or, Just use `createImgMapAreaResponsiveListener` for above does.

``` js
// src/plugins/responsive-img-map-area.js

import { createImgMapAreaResponsiveListener } from 'img-map-area'

createImgMapAreaResponsiveListener()

```

# APIs

## `responsiveImgMapArea`

Handles a single img element, making the associated map area responsive.

```js
import { responsiveImgMapArea } from 'img-map-area'
```

**parameters**

- **imgEl**: `HTMLImageElement`.

## `createImgMapAreaResponsiveListener`

Create a listener to make map area responsive.

```js
import { createImgMapAreaResponsiveListener } from 'img-map-area'
```

**parameters**

- **imgSelector**: A selector string, default is `.map-area-img`.