我有一个像这样的部分 - <section id="left_side"> //Some crap here.</section>
还有一个像这样的元素 - <aside id="right_side"> //Some crap here.</aside>
我想做的是当 aside 容器的高度大于 section 容器时,然后使用 jQuery 我希望它的高度扩展并大于或等于 aside 容器。
但是,同时,如果 aside 小于部分容器,那么我希望它的高度扩展并等于部分容器。
我完全不知道如何使用 jQuery 来做到这一点。
最佳答案
$('.section-container').on('adjustNeighbors', '#leftside,#rightside', function () {
var thisHeight = $(this).outerHeight();
var sectionToResize = $(this).is('#leftside') ? '#rightside' : '#leftside';
$(sectionToResize).css('height', thisHeight + 'px');
});
然后像这样触发它..
function someFunction(){
// some code that resized #leftside or #rightside
thatSection.trigger('adjustNeighbors');
}
关于jquery - 使用jquery动态设置两个元素的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12225145/