18 lines
549 B
JavaScript
18 lines
549 B
JavaScript
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
const title = document.querySelector("section#title-slide h1.title");
|
|
if (!title) return;
|
|
|
|
const lineHeight = parseFloat(getComputedStyle(title).lineHeight);
|
|
const maxHeight = lineHeight * 1.5; // 限制为两行
|
|
|
|
let fontSize = parseFloat(getComputedStyle(title).fontSize);
|
|
|
|
// 循环缩小字体直到标题高度 <= 两行
|
|
while (title.scrollHeight > maxHeight && fontSize > 10) {
|
|
fontSize -= 1;
|
|
title.style.fontSize = fontSize + "px";
|
|
}
|
|
});
|
|
</script>
|