【发布时间】:2023-02-11 07:29:52
【问题描述】:
我有一个 wordpress 网站。 该代码有时有效。我很困惑为什么有时它会正确地添加 mastHeight 的边距而其他时候它会增加额外的边距。我怀疑它必须对脚本运行时未完全加载的页面执行某些操作。有人可以指导我正确的方向吗?
这是我在网站上运行的代码:
<script>
jQuery(document).ready(function($) {
// When the window resizes
$(window).on('resize', function () {
// Get the height + padding + border of `#masthead`
var mastHeight = $("#global-header-section").innerHeight();
// Add the height to `.site-content`
$("#et-main-area").css('margin-top', mastHeight);
});
// Trigger the function on document load.
$(window).trigger('resize');
});
</script>
【问题讨论】: