francoischalifour / medium-zoom

🔎🖼 A JavaScript library for zooming images like Medium
https://medium-zoom.francoischalifour.com
MIT License
3.58k stars 160 forks source link

Vitepress support #184

Open prashantnirgun opened 2 years ago

prashantnirgun commented 2 years ago

I started migrating from vuepress to vitepress then I realize I been using this zoom plugin. its been important for me. Is there any way out where I can use this plugin inside vitepress markdown file ?

If anyone knows any article or solution please share

zam157 commented 1 year ago

Check this issue and comment, that might be help

tobiasdalhof commented 1 year ago

If you create your own vitepress theme, you can integrate medium-zoom as follows:

import type { Theme } from 'vitepress'
import { inBrowser, useRoute } from 'vitepress'
import mediumZoom from 'medium-zoom'
import { nextTick, watch } from 'vue'
import Layout from './Layout.vue'
import NotFound from './NotFound.vue'

export default <Theme>{
  Layout,
  NotFound,
  setup() {
    const route = useRoute()
    watch(
      () => route.path,
      () => nextTick(() => {
        if (inBrowser)
          mediumZoom('[data-zoomable]')
      }),
      { immediate: true },
    )
  },
}

Add data-zoomable data attribute in markdown:

![alt](src){data-zoomable}