1.0.1 • Published 5 months ago

@m.dev/imagnify v1.0.1

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
5 months ago

Hero

Imagnify is a simple and lightweight library to add zoom functionality to images.

Features

  • Lightweight and simple to use
  • Set higher resolution image for zoom
  • Zoom to original size maintaining aspect ratio
  • Customizable styles
  • Responsive

Installation

NPM
npm install @m.dev/imagnify
CDN
<!-- Bundle -->
<script src="https://unpkg.com/@m.dev/imagnify"></script>

<!-- Or core and style separately -->
<script src="https://unpkg.com/@m.dev/imagnify/core"></script>
<script src="https://unpkg.com/@m.dev/imagnify/style"></script>

Usage

import imagnify from '@m.dev/imagnify'

imagnify()

The default package is a bundle that includes the core and the style. If you need, you can import them separately.

import imagnify from '@m.dev/imagnify/core'
import '@m.dev/imagnify/style'

Then, add data-zoom attribute to the images, unless another selector has been specified (see options).

<img src="image.jpg" data-zoom />

If you want to specify a higher resolution image for the zoom, you can set it as the value of the data-zoom attribute.

<img src="image.jpg" data-zoom="image-hd.jpg" />

Options

OptionTypeDefaultDescription
selectorstringdata-zoomThe selector for the images NodeList.
backgroundstring'white'The background color for the overlay. Can be any valid CSS color.
marginnumber10The margin in pixels around the image.
opacitynumber0.8The opacity of the zoomed image. From 0 to 1.

Example:

imagnify({
  selector: '.zoom-image',
  background: '#000',
  margin: 25,
  opacity: 0.5,
})

License

This project is licensed under the GPL-3.0-or-later license.

1.0.1

5 months ago

1.0.0

5 months ago