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

yet-another-medium-zoom

v0.4.2

Published

Highly configurable medium-like lightbox

Downloads

2,096

Readme

Yet Another Medium Zoom

codecov david license

YAMZ is a lightbox library heavily inspired by Medium.

It provides an easy way to add smooth, minimalistic, and highly customizable Medium-like zooming to your images.

Usage

To use the library, you simply tell it which images to bind to:

import yamz from "yet-another-medium-zoom";

const $images = [...document.querySelectorAll("img, picture")];
yamz.bind($images);

That's it. The library will automatically extract the appropriate high-res source from your images if you are using srcset, and will otherwise just use the image's own source (or a high-res source you specify).

Configuration

If you want to have more control over what's displayed, you may want to change some of the options. You can set an option globally, or you can specify the options on a per-image basis. This can be done in JavaScript when you open the lightbox, or in HTML by specifying the options on the image you bind to as data attributes.

<!-- set the options as data attributes -->
<img src="example.png" data-scroll-allowance="-1" data-duration="600" />
/* or specify them when you open the lightbox programmatically */
import yamz from "yet-another-medium-zoom";

yamz.setOptions({
    // set options globally
    /* ... */
});
const $img = document.querySelector("img");
yamz.open($img, {
    // set options on a per-image basis
    /* ... */
});

The following options are available:

| Name | Data attribute | Type | Default value | Description | | ------------------- | ----------------------- | ------------------------------------------------------- | --------------: | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | scrollAllowance | data-scroll-allowance | number | 128 | How much the user can scroll before the lightbox is closed. -1 to disable | | duration | data-duration | number | 300 | How long the animation should take, measured in milliseconds | | container | None | HTMLElement | document.body | The element to render the lightbox inside | | class | data-class | string | null | Class to give to the lightbox element. Mostly useful for styling | | highres | data-highres | string | null | URL of the high-res image to load. Can't be set globally | | caption | data-caption | string \| HTMLElement | null | String or element to insert as a caption below the image. Can't be set globally | | album | data-album | { img: HTMLElement, opts?: {} }[] | null | If set, the album that an image belongs to. Can be specified in HTML by using a string - all images with the same album string will then be considered part of the album. Can't be set globally | | wrapAlbum | None | boolean | false | Whether to wrap albums, so you can press left on the first image to go to the last one, and vice versa | | lightboxGenerator | None | (img: HTMLElement, opts: ImageOptions) => HTMLElement | null | Function which generates the lightbox, if you want to use a custom one. See below for more information |

Advanced Customization

There are two main ways to perform more in-depth customization of the lightbox:

CSS / DOM customization

You can style the lightbox however you want by simply using CSS to overwrite the built-in styles. You can also change the DOM structure of the lightbox by using the lightboxGenerator option, which lets you completely change what the lightbox contains. You can see an example of this on the project website. The animation will automatically adapt to your new styles.

Plugins

Plugins can be created if you need more advanced control. These are implemented as functions that augment a given YAMZ instance with whatever features the plugin implements. These plugins can then be composited if you want to use more than one at a time. An example of this can be seen in our main export.

Both the caption and album support are actually implemented as plugins (that are enabled by default), so if you want to create your own plugin it might be useful to reference the implementation of the caption or album plugins.