Git Product home page Git Product logo

mouse-wheel-zoom's Introduction

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 allows 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

Property Description Default
element DOM element to zoom none
zoomStep Size change for each step, relative to 1 = initial size .1

Returned object

Method Description
reset Rest current zoom level and position
setSrc Change image src
setSrcAndReset Change image src and reset
dispose Remove 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

mouse-wheel-zoom's People

Contributors

z3ut avatar

Watchers

James Cloos avatar

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.