fix: hide scrollbars on capturing (#7867)

This commit is contained in:
one 2025-07-06 19:51:59 +08:00 committed by GitHub
parent 84b4ae0634
commit 8ab4682519
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -49,3 +49,11 @@ pre:not(.shiki)::-webkit-scrollbar-thumb {
--color-scrollbar-thumb: var(--color-scrollbar-thumb-light);
--color-scrollbar-thumb-hover: var(--color-scrollbar-thumb-light-hover);
}
/* 用于截图时隐藏滚动条
* FIXME: 临时方案因为 html-to-image 没有正确处理伪元素
*/
.hide-scrollbar,
.hide-scrollbar * {
scrollbar-width: none !important;
}

View File

@ -68,6 +68,9 @@ export const captureScrollableDiv = async (divRef: React.RefObject<HTMLDivElemen
const originalScrollTop = div.scrollTop
// Hide scrollbars during capture
div.classList.add('hide-scrollbar')
// Modify styles to show full content
div.style.height = 'auto'
div.style.maxHeight = 'none'
@ -134,6 +137,9 @@ export const captureScrollableDiv = async (divRef: React.RefObject<HTMLDivElemen
} catch (error) {
console.error('Error capturing scrollable div:', error)
throw error
} finally {
// Remove scrollbar hiding class
divRef.current?.classList.remove('hide-scrollbar')
}
}