Files
phaten-audio/assets/javascripts/extra.js
PhatenIoT-yan 3a5820f4e9 添加en和zh
2025-05-14 15:25:41 +08:00

51 lines
2.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
function checkForm() {
alert('eee');
}
document.addEventListener('DOMContentLoaded', function() {
// 页面内容溢出检测函数
function checkPageOverflow() {
// 获取所有页面元素
var pages = document.querySelectorAll('.page');
pages.forEach(function(page) {
// 获取页面内容高度
var contentHeight = 0;
Array.from(page.children).forEach(function(child) {
contentHeight += child.offsetHeight;
});
// 获取页面可用高度 (减去内边距)
var pageStyles = window.getComputedStyle(page);
var paddingTop = parseFloat(pageStyles.paddingTop);
var paddingBottom = parseFloat(pageStyles.paddingBottom);
var availableHeight = page.offsetHeight - paddingTop - paddingBottom;
// 检查是否溢出
if (contentHeight > availableHeight) {
page.setAttribute('data-overflow', 'true');
// 如果下一个元素不是 page-break添加一个
var nextElement = page.nextElementSibling;
if (!nextElement || !nextElement.classList.contains('page-break')) {
var pageBreak = document.createElement('div');
pageBreak.className = 'page-break';
page.parentNode.insertBefore(pageBreak, page.nextSibling);
}
} else {
page.removeAttribute('data-overflow');
}
});
}
// 初始检查
checkPageOverflow();
// 窗口大小改变时重新检查
window.addEventListener('resize', checkPageOverflow);
// 图片加载后重新检查(图片会影响内容高度)
document.querySelectorAll('img').forEach(function(img) {
img.addEventListener('load', checkPageOverflow);
});
});