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 🙏

© 2025 – Pkg Stats / Ryan Hefner

img-previewer

v2.1.7

Published

A light wight javascript image viewing plugin with smooth animation

Downloads

116

Readme

Img-previewer Js

GitHub license GitHub stars

Lightweight and powerful javascript image preview plug-in, silky animation allows you to elegantly preview the images in your website. Out of the box, you don't need extra configuration (by default) or change the page html code structure, you can easily enable the plugin in any type of website and upgrade your user experience

These functions are provided:

  1. Silky, interruptible transition animation
  2. Use mouse wheel to zoom picture
  3. Icon drag picture
  4. Previous & Next
  5. Shortcut key support
  6. Support for mobile gestures (zoom in with two fingers)
  7. Multi-language internationalization support
  8. Picture loading monitor

Other languages: English, 简体中文.

tips: For performance reasons, the mobile terminal does not do swiper

Example

Preview

how to use

NPM

npm i img-previewer
# or
yarn add img-previewer

CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/img-previewer.min.js"></script>

Enable

//js
import ImgPreviewer from'img-previewer'
//css
import'img-previewer/dist/index.css'

const imgPreviewer = new ImgPreviewer(css selector,{options...})

Property list

| | Type | Description | Default Value | | ------------- | ------ | ----------------------------------------------------------------------------------- | ----------------------------------------------- | | fillRatio | number | The proportion of the image that fills the preview area | 0.9(90%) | | dataUrlKey | string | The key of the image address value | src | | triggerEvent | string | trigger event | click | | imageZoom | object | Zoom image configuration | {min: 0.1,max: 5,step: 0.1} | | style | object | Style configuration | {modalOpacity: 0.6,headerOpacity: 0,zIndex: 99} | | i18n | object | tooltips International configuration | null | | bubblingLevel | number | Bubble to detect whether the parent element of the image is hidden by the css style | 0 |

Optional values for triggerEvent are: click and dblclick

bubblingLevel Description

You should try to use this property when you notice an abnormal image hide animation. Because when the image or the parent element of the image is hidden by some CSS styles, it cannot be detected through the js api, so you need to pass in the correct upward lookup level according to the actual situation to help the plug-in complete the correct hiding animation. As shown below, the correct bubblingLevel is at least 3

for performance considerations, it is not recommended to fill in this attribute value at will

<div style="opacity:0"> <!-- 3 -->
	<div> <!-- 2 -->
		<img src="" alt="" /> <!-- 1 -->
	</div>
</div>

Notice: Currently detecting that an element or parent element is hidden by a css style only supports the following styles:

  • opacity: 0;
  • height: 0;
  • width: 0;
  • visibility: hidden;

options.imageZoom

| | Description | Default value | | ---- | ---------------------------------------------- | ------------- | | min | Minimum zoom ratio | 0.1(10%) | | max | Maximum zoom ratio | 5(500%) | | step | The change ratio of the scroll wheel each time | 0.1 |

options.style

| | Description | Default value | | ------------- | ------------------------------ | ------------- | | modalOpacity | Preview area mask transparency | 0.6 | | headerOpacity | Toolbar transparency | 0 | | zIndex | Level of plug-in rendering | 99 |

options.i18n

Simplified Chinese and English are supported by default, others need to be configured by themselves

| | Description | | ------------ | ------------- | | RESET | Reset | | ROTATE_LEFT | Rotate Left | | ROTATE_RIGHT | Rotate right | | CLOSE | Close preview | | NEXT | Next | | PREV | Previous |

api methods

| Method name | Description | | ------------------ | -------------------------- | | update() | update image els | | getTotalIndex() | get total image el numbers | | show(index:number) | show index image | | next() | goto next | | prev() | goto prev |

hot key

| Button | Description | | ------ | ------------- | | Esc | Close preview | | <= | Previous | | => | Next |

Update picture

Some dynamically updated picture lists use

const imgPreviewer = new ImgPreviewer('body')
// Called after the image is rendered on the page
imgPreviewer.update()

play slideshow

let timer = null
function play() {
	timer && clearInterval(timer)
	let index = 0
	a.show(index)
	timer = setInterval(() => {
		if (index < a.getTotalIndex()) {
			index++
		} else {
			index = 0
		}
		a.show(index)
	}, 2000)
}
play()