1.1.5 • Published 5 years ago

mouse-wheel-zoom v1.1.5

Weekly downloads
295
License
ISC
Repository
github
Last release
5 years ago

Mouse wheel zoom

Zoom html elements with mouse wheel.

Live demo

Installation

npm i mouse-wheel-zoom

Usage

import { mouseWheelZoom } from 'mouse-wheel-zoom';

const wz = mouseWheelZoom({
  element: document.querySelector('[data-wheel-zoom]'),
  zoomStep: .25  
});

// reset zoom
wz.reset();

Description

Ispired by Jack Moore wheelzoom This package allow to view image and copy image url after right-click on image.

For given html element mouse-wheel-zoom will replace it with inline-block div wrapper. Wrapper will have two elements - original element with absolute positioning and cloned element with zero opacity. Wrapper size will be determined by zero opacity element, original element with absolute positioning can be moved\resized with mouse.

For element

<img class="image" data-wheel-zoom src="./cat.jpeg">

Mouse-wheel-zoom will replace it with

<div style="display: inline-block; position: relative; overflow: hidden;">
  <img class="image" data-wheel-zoom="" src="./cat.jpeg" style="opacity: 0;">
  <img class="image" data-wheel-zoom="" src="./cat.jpeg" style="position: absolute; top: 0; left: 0;">
</div>

Warning! Do not use for zooming html elements with id. After cloning page will have 2 elements with same id.

Documentation

Config object

PropertyDescriptionDefault
elementDOM element to zoomnone
zoomStepSize change for each step, relative to 1 = initial size.1

Returned object

MethodDescription
resetRest current zoom level and position
setSrcChange image src
setSrcAndResetChange image src and reset
disposeRemove zooming element from page

Development

Project require globally installed parcel. Run npm run start and see demo page with live reload on http://localhost:1234

1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago