All Projects β†’ mvoloskov β†’ fast-image-zoom

mvoloskov / fast-image-zoom

Licence: BSL-1.0 License
🏞 Fast image zoom on click as seen on popular publishing platform

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to fast-image-zoom

Medium Zoom
πŸ”ŽπŸ–Ό A JavaScript library for zooming images like Medium
Stars: ✭ 2,799 (+13228.57%)
Mutual labels:  medium, image-zoom
medium-unlocker
Read Medium content without limit!
Stars: ✭ 127 (+504.76%)
Mutual labels:  medium
blog-template
Template for the Jekyll-powered elementary blog
Stars: ✭ 34 (+61.9%)
Mutual labels:  medium
Medium-Python-Neural-Network
This code is part of my post on Medium.
Stars: ✭ 58 (+176.19%)
Mutual labels:  medium
Self-Driving-Car-Steering-Simulator
The aim of this project is to allow a self driving car to steer autonomously in a virtual environment.
Stars: ✭ 15 (-28.57%)
Mutual labels:  medium
code-medium
Browser extension that simplifies writing code in Medium posts. Quickly create and edit Github Gists without leaving the editor
Stars: ✭ 59 (+180.95%)
Mutual labels:  medium
hosts
θ‡ͺεŠ¨η”Ÿζˆ Hosts ζ–‡δ»ΆοΌŒη§‘ε­¦δΈŠη½‘
Stars: ✭ 30 (+42.86%)
Mutual labels:  medium
zoom.ts
A lightweight TypeScript library for image zooming, as seen on Medium.
Stars: ✭ 44 (+109.52%)
Mutual labels:  medium
readtime
Calculates the time some text takes the average human to read, based on Medium's read time forumula.
Stars: ✭ 93 (+342.86%)
Mutual labels:  medium
artigo-solid-medium
Implementaçáes dos exemplos demonstrados no artigo: https://bit.ly/2o97vY1
Stars: ✭ 28 (+33.33%)
Mutual labels:  medium
kuote
Create beautiful Medium-like quotes, perfect for sharing on Twitter or Instagram.
Stars: ✭ 11 (-47.62%)
Mutual labels:  medium
MediumAppFlutter
Flutter recreation of the UI of the Medium android app
Stars: ✭ 62 (+195.24%)
Mutual labels:  medium
react-simple-image-zoom
Simple image zoom component for react
Stars: ✭ 12 (-42.86%)
Mutual labels:  image-zoom
medium-sdk-elixir
Elixir SDK for the Medium.com API. 🌐
Stars: ✭ 19 (-9.52%)
Mutual labels:  medium
bypass-paywalls-chrome-clean-magnolia1234
Bypass Paywalls Chrome Clean (GitLab proxy)
Stars: ✭ 32 (+52.38%)
Mutual labels:  medium
image-zoom
smooth, iOS/medium.com style thumbnail viewing
Stars: ✭ 35 (+66.67%)
Mutual labels:  image-zoom
webpack-2.0-from-scratch
Guide on how to setup a Webpack config from scratch.
Stars: ✭ 72 (+242.86%)
Mutual labels:  medium
React-Medium-Blog
React blog page which consist of last ten medium posts. The blog card is created using shards React and React application.
Stars: ✭ 14 (-33.33%)
Mutual labels:  medium
medium-sdk-php
Open source SDK for integrating Medium's OAuth2 API into your PHP application.
Stars: ✭ 79 (+276.19%)
Mutual labels:  medium
medium-to-wordpress-migration
Script to export medium blogs to wordpress rss xml format
Stars: ✭ 15 (-28.57%)
Mutual labels:  medium

Dependencies npm License Sponsor this project My github My twitter

Demo   β€’   Configuration   β€’   Author

🏞 Fast Image Zoom

Image zoom on click as seen on popular publishing platform.

What it does?

You click on an image and it smoothly zooms in or out to fit screen. You click again β€” it smoothly goes back to normal. You scroll β€” it also goes back.

Why is it better than alternatives?

  • πŸ›  Framework-agnostic β€” works with everything from Knockout.js to Web Components
  • πŸ‘Œ Zero-dependency
  • 🧬 Perfect for dynamic content, mutation-agnostic β€” you can do whatever you want with images, it'll work
  • ⚑️ Blazing fast β€” no matter if it's 10 images or 10000, it uses only two event listeners. Not per image, just two listeners. Complexity is always O(1)
  • πŸ€“ Powered by quirky math to precisely calculate everything and do the trick with only one transformation
  • πŸ¦‹ Looks good on both dark and light modes
  • 🍦 Zero-configuration by default but extensible when you need it
  • πŸ—Ώ Works flawlessly even on iOS Safari, in every orientation, with every image no matter the size and dimensions

Basic usage

npm install fast-image-zoom --save

or

yarn add fast-image-zoom
import imageZoom from 'fast-image-zoom'
imageZoom()

Alternative β€” use CDN

<script src="https://cdn.jsdelivr.net/gh/mvoloskov/fast-image-zoom/dist/fast-image-zoom.min.js"></script>
<script>
  imageZoom()
</script>

That's it!

How it works

Plugin targets meaningful, content images:

<!-- yes -->
<img src="foo.jpg" alt="Cute kitten" />

<!-- no -->
<img src="bar.jpg" />
<img src="bar.jpg" alt="" />

Configuration

Here are the defaults:

imageZoom({
    selector: `img[alt]:not([alt=""]):not([data-image-zoom-disabled])`,
    cb: () => {},
    exceed: false,
    padding: 20,
})
  • selector (string) is used to target images. By default it only targets meaningful images (e.g. ones with alt), so your icons won't be magnified on click.

  • cb (function) fires after the plugin is initialized.

  • exceed (boolean) defines whether images should exceed their natural size when zoomed. For example if you zoom 100x100 image on a 1080p screen with exceed: false, its final size will be 100px, meanwile with exceed: true it will be 1080px.

  • padding (integer) defines a gap in pixels between a zoomed image and the closest edge of the viewport.

Note that if exceed is false and a smaller image appear to have a larger gap between its edge and the edge of the viewport, padding won't be added. For example, if you zoom an 100x100 image on a 1080p screen and your padding is set to 20, a natural gap between an image and the viewport edge would be (1080 - 100) / 2 = 490, thus there is no need to add that 20px gap.

Only pixels are supported by now.

Setting exceed per image

You can explicitly define exceed for a specific picture via a data-attribute:

<img src="..." alt="..." data-image-zoom-exceed="true">

Disabling the plugin for the specific image

You can disable zooming for any image you like, even if it has alt:

<img src="..." alt="..." data-image-zoom-disabled>

Note that if you redefine the selector in a way that doesn't account data-image-zoom-disabled attribute, this feature will stop working.

Restyling

You can always hack the plugin redefining straightforward CSS:

Changing a timing function

.image-zoom,
.image-zoom-wrapper::after {
    transition-timing-function: ease-in-out;
}

Changing the background color

.image-zoom-wrapper::after {
    background-color: hotpink;
}

Anatomy

  • .image-zoom-wrapper β€” element that wraps every image. Mimicks its display property. We use it to add page background and slightly separate the zoomed image from what is behind.
  • .image-zoom-wrapper-zoomed β€” the same wrapper but when image is zoomed.
  • .image-zoom β€” image itself that was processed and is interactive ready to zoom.
  • .image-zoom-zoomed β€” zoomed image.

Disabling the plugin

Being called, plugin returns the destroy function that you may call to remove event listeners. It will also remove related styles from <head> and from images themselves.

const destroy = imageZoom()

// don't need it anymore
destroy()

Limitations

  • img inline styles will be destroyed. Use CSS selectors to stylize images.
  • img shouldn't have transforms. If needed, wrap it with a container and apply transforms there instead.
  • :root's overflow-x will be hidden

Enjoy!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].