Coder Social home page Coder Social logo

jaeyeophan / gatsby-remark-images-medium-zoom Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 3.0 272 KB

🀳medium-zoom plugin for gatsby! Raise UX of user who visit your gatsby site with this plugin

Home Page: https://www.npmjs.com/package/gatsby-remark-images-medium-zoom

License: MIT License

JavaScript 100.00%
gatsby plugin medium medium-zoom image remark

gatsby-remark-images-medium-zoom's Introduction

gatsby-remark-images-medium-zoom-plugin πŸ‘‹

npm version

Twitter: JbeeLjyhanll

medium-zoom plugin for gatsby with gatsby-remark-images

πŸ—‚ Use Case

🚚 Install

$ npm install --save gatsby-remark-images-medium-zoom
$ npm install --save gatsby-remark-images gatsby-transformer-remark
# or
$ yarn add gatsby-remark-images-medium-zoom
$ yarn add gatsby-remark-images gatsby-transformer-remark

πŸš€ How to use

πŸ‘‰ This plugin requires gatsby-remark-images and either gatsby-transformer-remark or gatsby-plugin-mdx.

The linkImagesToOriginal option needs to be set to false.

Use with gatsby-transformer-remark

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        {
          resolve: `gatsby-remark-images`,
          options: {
            maxWidth: 590,
            linkImagesToOriginal: false // Important!
          }
        },
        {
          resolve: `gatsby-remark-images-medium-zoom`, // Important!
          options: {
            //...
          }
        }
      ]
    }
  }
]

Use with gatsby-plugin-mdx

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-plugin-mdx`,
    options: {
      // a workaround to solve mdx-remark plugin compat issue
      // https://github.com/gatsbyjs/gatsby/issues/15486
      plugins: [
        `gatsby-remark-images`,
        `gatsby-remark-images-medium-zoom` // Important!
      ],
      gatsbyRemarkPlugins: [
        {
          resolve: `gatsby-remark-images`,
          options: {
            maxWidth: 590,
            linkImagesToOriginal: false // Important!
          }
        },
        {
          resolve: `gatsby-remark-images-medium-zoom`, // Important!
          options: {}
        }
      ]
    }
  }
]

βš™ Options

https://github.com/francoischalifour/medium-zoom#options

Property Type Default Description
margin number 0 The space outside the zoomed image
background string "#fff" The background of the overlay
scrollOffset number 40 The number of pixels to scroll to close the zoom
container string | HTMLElement | object null The viewport to render the zoom in
template string | HTMLTemplateElement null The template element to display on zoom
zIndex number 999 The number of z-index of overlay element and image element

In addition, this plugin has its own options:

Property Type Default Description
excludedSelector string null The selector of excluded images to zoom in
includedSelector string null The selector of included images to zoom in on in addition to the ones parsed by gatsby-remark-images

Author

πŸ‘€ JaeYeopHan (Jbee)

Show your support

Give a ⭐️ if this project helped you!

Written by @Jbee✌

gatsby-remark-images-medium-zoom's People

Contributors

bripkens avatar jaeyeophan avatar karlhorky avatar lex111 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gatsby-remark-images-medium-zoom's Issues

IE/Edge - ReferenceError: 'PerformanceObserver' is not defined

After configuring gatsby-remark-images-medium-zoom on my website www.abhith.net, I noticed that the site stopped rendering on Edge and in the IE.

[object Error]: {description: "'PerformanceObserver' is not defined", message: "'PerformanceObserver' is not defined", number: -2146823279, stack: "ReferenceError: 'PerformanceObserver' is not defined at Anonymous function (https://www.abhith.net/app-739e00f33abe6606836d.js:1:40133) at g (https://www.abhith.net/app-739e00f33abe6606836d.js:1:39773) at Anonymous function (https://www.abhith.net/app-739e00f33abe6606836d.js:1:260951) at Array.prototype.map (native code) at e.apiRunner (https://www.abhith.net/app-739e00f33abe6606836d.js:1:260789) at _ (https://www.abhith.net/app-739e00f33abe6606836d.js:1:153724) at n.componentDidMount (https://www.abhith.net/app-739e00f33abe6606836d.js:1:156049) at yu (https://www.abhith.net/commons-49ba44192dc7b381ca18.js:1:179519) at t.unstable_runWithPriority (https://www.abhith.net/commons-49ba44192dc7b381ca18.js:1:3567) at Ga (https://www.abhith.net/commons-49ba44192dc7b381ca18.js:1:124175)"}

Then I checked https://gatsby-starter-bee.netlify.com/development/hello/, and it was rendering fine on Edge and all.

Even though there is no mention of any polyfill requirements in the README, I fixed the issue by adding the polyfill @fastly/performance-observer-polyfill

I just want to check whether its the right way to fix this issue.

Source code
Linked issue

Not working before page refresh

Hello,
if I access my case studies (markdown) via the page generator by slug, the plugin won't work initially, I need to manually refresh the markdown page for it to work properly, any ideas?

Thanks in advance.

Flicker with white background + alt tag on Safari (macOS + iOS)

Hello, I've noticed on all Gatsby sites using this plugin there's this bug only in Safari where the image will turn white with the alt text on the upper left for a brief millisecond. I am not seeing this issue on Chrome or Firefox.

μ•ˆλ…•ν•˜μ‹­λ‹ˆκΉŒ. λͺ¨λ“  이 ν”ŒλŸ¬κ·ΈμΈμ„ μ‚¬μš©μžˆλŠ” κ°ΈμŠ€λΉ„μ‚¬μ΄νŠΈκ°€ μ‚¬νŒŒλ¦¬μ— 버그 μžˆμŠ΅λ‹ˆλ‹€. λΉ λ₯Έ 흰색 ν”Œλž˜μ‹œκ°€ 있고 μ™Όμͺ½ 상단에 μΊ‘μ…˜λ„ λ‚˜νƒ€λ‚©λ‹ˆλ‹€. 크둬와 νŒŒμ΄μ–΄ν­μŠ€μ—λŠ” 버그가 μ—†μŠ΅λ‹ˆλ‹€.

https://gatsby-starter-bee.netlify.app/development/hello/

macOS Monterey 12.5:

Bug

iOS 15.5:

Mobile

Zoom breaks when browser viewport size changes e.g. portrait to landscape or vice versa

While testing the responsiveness of this plug-in with gatsby, I noticed the zoom capability will disappear after the browser viewport resolution is changed, e.g. portrait to landscape or vice versa. A common use case when viewing with mobile device.

By examine the DOM, before the viewport size change:

<span class="gatsby-resp-image-wrapper" ...>
  <span class="gatsby-resp-image-background-image" ...></span>
  <img
    class="gatsby-resp-image-image medium-zoom-image"
    src="..."
    srcset="..."
    "
    ...
  />
</span>

after the browser viewport resolution is changed, the class medium-zoom-image that use to be applied against <img> tag will disappear and hence the loss of the zoom functionality:

<span class="gatsby-resp-image-wrapper" ...>
  <span class="gatsby-resp-image-background-image" ...></span>
  <img
    class="gatsby-resp-image-image"
    src="..."
    srcset="..."
    "
    ...
  />
</span>

Current Workaround

While not ideal, the zoom functionality can be restored with another manual refresh after the viewport resolution change.

Background option does not seem to work with mdx

I recently switched from using remark to mdx and I noticed that the background option does not seem to work anymore. Here is the mdx object in my gatsby-config.js file:

...
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        plugins: [
          `gatsby-remark-images`,
          `gatsby-remark-images-medium-zoom` // Important!
        ],
        extensions: [`.md`, `.mdx`],
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-images`,
            options: {
              maxWidth: 1600,
              withWebp: true,
              linkImagesToOriginal: false,
              quality: 95,
            },
          },
          {
            resolve: `gatsby-remark-images-medium-zoom`, // Important!
            options: {
              background: "rgba(26,26,26,0.75)",
            },
          },
          ...
        ],
      },
    },
...

When the mdx is rendered, however, the .medium-zoom-overlay appears like this:

<div class="medium-zoom-overlay" style="background: rgb(255, 255, 255);"></div>

Currently my workaround is to set the background using a css overwrite, but I would prefer to use the background option if that's possible. Any help on fixing this would be greatly appreciated. Thank you!

Zoomed image not full resolution.

Zoomed image is not the original(full resolution) image, but the same image provided for the current view port size.
Using this config:

{
              resolve: `gatsby-remark-images`,
              options: {
                maxWidth: 960,
                withWebp: false,
                linkImagesToOriginal: false,
              },

Zoomed image is stretched and still 960px width, event if the screen is wider.
I guess the most correct behavior is to use the original(full resolution) image.

transparent png background

2 questions:

  1. Is it supposed to work with transparent PNG background? In my case it just substitutes transparent background with default white

  2. background option does not seem to be working for me

png_transparent

Image itself
4lvl-page-tables

Gatsby image config:

{
  resolve: `gatsby-plugin-mdx`,
  options: {
    plugins: [
      `gatsby-remark-images`,
      `gatsby-remark-images-medium-zoom` // Important!
    ],
    gatsbyRemarkPlugins: [
      {
        resolve: `gatsby-remark-images`,
        options: {
          maxWidth: 590,
          linkImagesToOriginal: false, // Important!              
        }
      },
      {
        resolve: `gatsby-remark-images-medium-zoom`, // Important!
        options: {
          margin: 36,
          scrollOffset: 0,
          background: "#777"
        },
      }
    ],
  }
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`

Lag when opening images

Not sure if this performance issue is related to the plugin or size of my images or something else. But sometimes enlarging an image will take a couple of seconds to happen.

demo_lag

not work

I try import this package for my gatsby blog, but he can not work,
nothing has changed in HTML, I view your demo and see how img in your HTML adds a lot of other atterbiute. there is no change in mine

image

Weird Delay after unzooming.

Hello JaeYeop, great work on this!

I have a small issue, that when I unzoom, for a period of around ~1 second, I can't zoom back in, nor do I have the zoom symbol anymore.

Thanks again for this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.