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

medium-zoom-juejin

v0.2.6

Published

Medium-like zoom on your pictures in pure JavaScript

Downloads

12

Readme

medium-zoom npm js-standard-style

Medium-like zoom on your pictures in pure JavaScript 🔎🖼

Install

$ npm install --save medium-zoom

Or download the minified version.

No dependencies.

Features

  • 🔎 Image selectionapply the zoom to a selection of images
  • 🖱 Mouse, keyboard and gesture friendlyclick anywhere, press a key or scroll away to dismiss the zoom
  • 🎉 Event handlingtriggers events when the zoom enters a new state
  • 🔧 Customizationset your own margin, background and scroll offset
  • 🔗 Link supportopens the link of the image in a new tab when a meta key is held ( or Ctrl)
  • 🖼 Image openerwhen no link, opens the image source in a new tab when a meta key is held ( or Ctrl)
  • 📱 Responsivescales on mobile and desktop
  • 🚀 Performant and lightweightshould be able to reach 60 fps

Usage

1. Import the script

<script src="node_modules/medium-zoom/dist/medium-zoom.min.js"></script>

Or:

const mediumZoom = require('medium-zoom')

2. Run the plugin

mediumZoom(<selector>, <options>)

By default, the zoom is applied to all scaled images (with HTML or CSS properties). You can specify the zoomable images with a CSS selector and add options.

Additionally, you can pass an array-like or an array of images to the plugin.

// CSS selector
mediumZoom('#cover')

// array-like
mediumZoom(document.querySelectorAll('[data-action="zoom"]'))

// array
const imagesToZoom = [
  document.querySelector('#cover'),
  ...document.querySelectorAll('[data-action="zoom"]')
]

mediumZoom(imagesToZoom)

API

Options

Options can be passed via a JavaScript object through the mediumZoom call.

| Properties | Type | Default | Description | |--------------|---------|----------|---------------------------------------------------------------------| | margin | integer | 0 | Space outside the zoomed image | | background | string | "#fff" | Color of the overlay | | scrollOffset | integer | 48 | Number of pixels to scroll to dismiss the zoom | | metaClick | boolean | true | Enables the action on meta click (opens the link / image source) |

mediumZoom('[data-action="zoom"]', {
  margin: 24,
  background: '#000',
  scrollOffset: 0,
  metaClick: false
})

Methods

.show()

Triggers the zoom.

const zoom = mediumZoom('#my-image')

zoom.show()

Emits an event show on animation start and shown when completed.

.hide()

Dismisses the zoom.

const zoom = mediumZoom('#my-image')

zoom.hide()

Emits an event hide on animation start and hidden when completed.

.toggle()

Shows the zoom when hidden, hides the zoom when shown.

const zoom = mediumZoom('#my-image')

zoom.toggle()

.update(<options>)

Updates and returns the options.

const zoom = mediumZoom('#my-image')

zoom.update({
  background: '#000'
})

.addEventListeners(type, listener)

Registers the specified listener on each target of the zoom.

const zoom = mediumZoom('[data-action="zoom"]')

zoom.addEventListeners('hidden', () => {
  // do something...
})

Events

| Event | Description | |------------------|---------------------------------------------------------------------| | show | Fired immediately when the show instance method is called | | shown | Fired when the zoom has finished being animated | | hide | Fired immediately when the hide instance method is called | | hidden | Fired when the zoom out has finished being animated |

const zoom = mediumZoom('#image-tracked')

zoom.addEventListeners('show', event => {
  // do something...
})

Examples

mediumZoom(imagesToZoom) })

</details>

<details>
 <summary>Margins, overlay, scroll offset and click</summary>
```js
mediumZoom({
  margin: 16,
  background: '#000',
  scrollOffset: 0,
  metaClick: false
})

button.addEventListener('click', () => zoom.show())

</details>

<details>
 <summary>Zoom counter</summary>
```js
let counter = 0
const zoom = mediumZoom('#image-tracked')

zoom.addEventListeners('show', event => {
  console.log(`"${event.target.alt}" has been zoomed ${++counter} times`)
})

Demo

View demo 🔎, go to the demo folder or read the article.

Dev

  • Install the dependencies: npm install
  • Watch changes: npm run dev

Contributing

Need more options? Send a pull request!

  1. Fork the repository
  2. Create a new branch
  3. Send a pull request 👌

License

MIT © François Chalifour