Skip to content

Commit

Permalink
feat: 图片增加缩放
Browse files Browse the repository at this point in the history
  • Loading branch information
LetTTGACO committed Feb 3, 2024
1 parent 65bb32c commit faf9b06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
4 changes: 4 additions & 0 deletions docs/.vitepress/theme/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
--vp-c-brand-2: #2a9d8f;
--vp-button-brand-hover-bg: #21867a;
}

.medium-zoom-image--opened {
z-index: 9999;
}
30 changes: 16 additions & 14 deletions docs/.vitepress/theme/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
import DefaultTheme from 'vitepress/theme';
import giscusTalk from 'vitepress-plugin-comment-with-giscus';
import { useData, useRoute } from 'vitepress';
import { inBrowser, useData, useRoute } from 'vitepress';
import './index.css'
import mediumZoom from 'medium-zoom';
import { onMounted } from 'vue';
import { nextTick, watch } from 'vue';
export default {
...DefaultTheme,
enhanceApp(ctx) {
DefaultTheme.enhanceApp(ctx);
// ...
},
setup() {
onMounted(() => {
let images = document.body.querySelectorAll("img");
console.log('images', images)
images.forEach((image) => {
if (image.alt !== "VitePress") {
// 图片添加点击放大功能
image.classList.add("zoom-image");
}
});
mediumZoom(".zoom-image");
});
// 获取前言和路由
const { frontmatter } = useData();
const route = useRoute();

watch(
() => route.path,
() => nextTick(() => {
if (inBrowser) {
const content = document.querySelector("#VPContent")
let images = content.querySelectorAll("img");
images.forEach((image) => {
image.classList.add("zoom-image");
});
mediumZoom(".zoom-image");
}
}),
{ immediate: true },
)
// 评论组件 - https://giscus.app/
giscusTalk({
repo: 'LetTTGACO/elog-docs',
Expand Down

0 comments on commit faf9b06

Please sign in to comment.