npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

imagezoomjs

v7.0.3

Published

my description

Downloads

9

Readme

ImageZoom.js

Image resizing using mouse wheel, range input slider and other elements to control scaling/zooming of images.

GitHub tag (latest by date) GitHub stars GitHub issues GitHub forks

Demo

Installation

npm i imagezoomjs

or

yarn add imagezoomjs

Babel

Babel is a next generation JavaScript compiler. One of the features is the ability to use ES6/ES2015 modules now, even though browsers do not yet support this feature natively.

import ImageZoom from "imagezoom.js"

Browserify/Webpack

There are several ways to use Browserify and Webpack. For more information on using these tools, please refer to the corresponding project's documention. In the script, including jQuery will usually look like this...

const ImageZoom = require("imagezoom.js");

AMD (Asynchronous Module Definition)

AMD is a module format built for the browser. For more information, we recommend require.js' documentation.

define(["imagezoom.js"], (ImageZoom) => {
    // your code ...
});

Vanilla JavaScript

<script src="../dist/imagezoom.min.js"></script>

Examples

A couple of examples are listed below. See the demo for more details.

Basic Usage

<div id="myWindow">
    <img id="myImage" src="https://picsum.photos/2400/1400" alt="Lorem Picsum" />
</div>
const myImage = document.getElementById('myImage');
const myImageZoom = new ImageZoom(myImage);

Image With Controls

<div class="container">
  <div class="row">
    <div class="col-12">
      <img id="myImage src="https://picsum.photos/2400/1200" alt="Lorem Picsum" />
    </div>
  </div>

  <div class="row">
    <div class="col-12">
      <div class="d-flex">
        <div class="col-1">
          <i data-zoom data-zoom-out class="fa fa-minus"></i>
        </div>

        <div class="col-10">
          <input data-zoom-range type="range" class="form-control-range">
        </div>

        <div class="col-1">
          <i data-zoom data-zoom-in class="fa fa-plus"></i>
        </div>
      </div>
    </div>
  </div>
</div>
const myImage = document.getElementById('myImage');
const rangeElement = document.querySelector('[data-zoom-range]');
const zoomInElement = document.querySelector('[data-zoom-in]');
const zoomOutElement = document.querySelector('[data-zoom-out]');

const options = {
  rangeElement: rangeElement,
  zoomInElement: zoomInElement,
  zoomOutElement: zoomOutElement
};

const myImageZoom = new ImageZoom(myImage, options);

Syntax & Parameters

The ImageZoom class constructor accepts up to two parameters: element and options.

const imageZoom = new ImageZoom(element, [, options]); // -> returns ImageZoom object

element Parameter

This is the element you wish to target for zooming/scaling functionality.

| Parameter | Type | Default | Description | |---|---|---|---| | element | HTMLElement or HTMLImageElement | null | The target element or image to enable zooming/scaling functionality on. |

options Parameter

This is an optional object with which you may alter default behavior. You may also pass in optional elements which may be enabled to control zooming/scaling of the primary element.

| Attribute | Type | Default | Description | |---|---|---|---| | minScale | Number | 1 | The minimum scale to which the image can be zoomed. 1 = 100%, 2 = 200%, etc. | | maxScale | Number | 10 | The maximum scale to which the image can be zoomed. 5 = 500%, 10 = 1000%, etc. | | speed | Number | 10 | Speed (or scale sensitivity) with which the image will be scaled. Measured in relative units. The larger the value, the smaller the increments between each step. | | element | HTMLElement or HTMLImageElement | null | The target element or image to enable zooming/scaling functionality on. | | rangeElement | HTMLInputElement | null | Optional: The input[type="range"] element to control scaling/zooming. | | zoomOutElement | HTMLElement | null | Optional: An element to control zooming out. See the Examples section for more details. | | zoomInElement | HTMLElement | null | Optional: An element to control zooming in. See the Examples section for more details. |

Example With options Parameter

const myImage = document.getElementById('myImage');

const options = {
  minScale: 1,
  maxScale: 10,
  speed: 10
};

const myImageZoom = new ImageZoom(myImage, options);

Contributors

Any contributions are welcomed. That said, this project has been through a number of iterations based on other project needs. So, it's only fair to acknowledge those whose code I have leveraged. The current iteration of this project is heavily lifted from https://github.com/kwdowik/zoom-pan. Prior iterations were also influenced by https://github.com/worka/vanilla-js-wheel-zoom.

License

MIT