feat(docs): improve image sizing and add global stylesheet
- Add style.css to head config for global styling - Refactor image height/width constraints with new classes - Adjust font size and image ratio thresholds - Add max-width constraints to prevent overflow
This commit is contained in:
@@ -99,21 +99,29 @@ export default {
|
||||
if (!naturalWidth || !naturalHeight) return
|
||||
|
||||
const ratio = naturalHeight / naturalWidth
|
||||
img.classList.remove('img-tall', 'img-very-tall', 'img-ultra-tall')
|
||||
img.style.width = 'auto' // 确保宽度自动,防止拉伸
|
||||
img.classList.remove(
|
||||
'img-tall',
|
||||
'img-very-tall',
|
||||
'img-ultra-tall',
|
||||
'img-limit-width',
|
||||
'img-limit-height'
|
||||
)
|
||||
|
||||
if (ratio > 3) {
|
||||
img.style.maxWidth = ''
|
||||
img.style.maxHeight = ''
|
||||
img.style.width = ''
|
||||
img.style.height = ''
|
||||
|
||||
if (ratio <= 1) {
|
||||
img.classList.add('img-limit-width')
|
||||
return
|
||||
}
|
||||
|
||||
img.classList.add('img-tall')
|
||||
if (ratio > 2.2) {
|
||||
img.classList.add('img-ultra-tall')
|
||||
img.style.maxHeight = '250px'
|
||||
} else if (ratio > 2) {
|
||||
} else if (ratio > 1.3) {
|
||||
img.classList.add('img-very-tall')
|
||||
img.style.maxHeight = '350px'
|
||||
} else if (ratio > 1.2) {
|
||||
img.classList.add('img-tall')
|
||||
img.style.maxHeight = '450px'
|
||||
} else {
|
||||
// 普通图片重置,避免复用 dom 时残留样式
|
||||
img.style.maxHeight = ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user