0

行。所以我使用下面的代码来调整 div 的高度,但由于设计是流畅的(我不希望它固定)。它工作得很好,但是一旦高度改变而不重新加载页面,高度就会有错误的值。

因此,我需要添加某种检查高度是否已更改,然后在不重新加载页面的情况下对其进行更新。我只想要 jQuery 解决方案,请不要提交任何 CSS 解决方案,因为该脚本也将用于不是其他人的孩子或父母的 div。

    $("#conten_area .sticky_note:has(.right_panel)").each(function (index, value) {
    var $this = $(this);
        current = $this.height();
        current = current+22;

        $this.find(".right_panel").height(current);

});
4

1 回答 1

1

以下应该做你需要的。没有侦听器可用于其他代码所做的更改或用户交互,除非您创建自定义事件并从其他代码触发它以运行该resizePanels函数。

function resizePanels() {
    $("#conten_area .sticky_note:has(.right_panel)").height( function(index, height) { 
        $this.find(".right_panel").height(height +22);
    });
}

/* resize panels when window resized*/
$(window).resize(function(){
     resizePanels();
})

/* resize panels on page load*/
$(function(){
    resizePanels();

})

​</p>

于 2012-10-21T19:31:00.033 回答