1.1.0 • Published 1 year ago

@websitebeaver/vue-magnifier v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

vue-magnifier

Npm package version license-image

This is a Vue 3 adaptation of react-magnifier, which is the original version. Someone else made a Svelte version, called svelte-magnifier as well.

Vue image zoom component

  • Simple and customizable
  • Supports touch screens
  • Allows different files for large image and magnifying glass (e.g. thumbnail and high-resolution image)

Demo

Usage

Install the package using NPM:

npm install @websitebeaver/vue-magnifier

Add the component to your Vue application:

<script setup lang="ts">
import VueMagnifier from '@websitebeaver/vue-magnifier'
import '@websitebeaver/vue-magnifier/styles.css'
</script>

<template>
  <VueMagnifier src="./path/to/image" width="500" />
</template>

Props

PropTypeDefaultDescription
src (required)StringURL/path of the large image
heightNumber/String'auto'Image height (absolute or relative values possible)
widthNumber/String'100%'Image width (absolute or relative values possible)
classNameString''Class which will be applied to the image wrapper
zoomImgSrcStringURL/path of the image inside the magnifying glass (if not specified, the large image will be used)
zoomFactorNumber1.5Factor by which the zoom image will be scaled (based on the size of the large image)
mgWidthNumber150Width of the magnifying glass in px
mgHeightNumber150Height of the magnifying glass in px
mgBorderWidthNumber2Border width of the magnifying glass in px
mgShapeString'circle'Shape of the magnifying glass (possible values: 'circle', 'square')
mgShowOverflowBooleantrueSet this to false to cut off the magnifying glass at the image borders. When disabling mgShowOverflow, it's recommended that you also set all offsets to 0
mgMouseOffsetXNumber0Horizontal offset of the magnifying glass in px when hovering with a mouse
mgMouseOffsetYNumber0Vertical offset of the magnifying glass in px when hovering with a mouse
mgTouchOffsetXNumber-50Horizontal offset of the magnifying glass in px when dragging on a touch screen
mgTouchOffsetYNumber-50Vertical offset of the magnifying glass in px when dragging on a touch screen
mgShowBooleantrueShow or hide magnifying glass. Doesn't exist in React or Svelte version.
mgCornerBgColorString#fffMagnifying glass corner background color. Doesn't exist in React or Svelte version.

Any other props will be passed down to the <img> element. This way, you can e.g. add an alt attribute to the image.

Events

EventTypeValueDescription
image:loadEvent-On image load. Doesn't exist in React or Svelte version.

Custom styling

.vue-magnifier__magnifier {
  /* Styles for <div> around image and magnifying glass */
}
.vue-magnifier__magnifying-glass {
  /* Styles for magnifying glass */
}
.vue-magnifier__magnifying-glass.vue-magnifier__circle {
  /* Styles for magnifying glass circle */
}
.vue-magnifier__magnifying-glass.vue-magnifier__visible {
  /* Styles for magnifying glass visible */
}