Skip to content

Commit

Permalink
Support zoom image
Browse files Browse the repository at this point in the history
  • Loading branch information
narumi147 committed May 12, 2024
1 parent 93ffa37 commit 7d2b41b
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 31 deletions.
20 changes: 18 additions & 2 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
// https://vitepress.dev/guide/custom-theme
import { h } from 'vue'
import type { Theme } from 'vitepress'
import { h, nextTick, onMounted, watch } from 'vue'
import { useRoute, type Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import './style.css'
import mediumZoom from 'medium-zoom'
// import AdSense from '../../components/AdSense.vue'

export default {
extends: DefaultTheme,
setup() {
// https://github.com/vuejs/vitepress/issues/854
const route = useRoute()
const initZoom = () => {
// mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' });
mediumZoom('.main img', { background: 'var(--vp-c-bg)' })
}
onMounted(() => {
initZoom()
})
watch(
() => route.path,
() => nextTick(() => initZoom())
)
},
Layout: () => {
return h(DefaultTheme.Layout, null, {
// 'aside-ads-before': () => h(AdSense),
Expand Down
8 changes: 8 additions & 0 deletions docs/.vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@
.DocSearch {
--docsearch-primary-color: var(--vp-c-brand-1) !important;
}

.medium-zoom-overlay {
z-index: 30;
}

.medium-zoom-image--opened {
z-index: 31;
}
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"author": "narumi",
"license": "MIT",
"dependencies": {
"medium-zoom": "^1.1.0"
},
"devDependencies": {
"@types/node": "^20.11.30",
"gray-matter": "^4.0.3",
Expand Down
71 changes: 42 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7d2b41b

Please sign in to comment.