我想知道是否有办法让父容器在使用slideup()时保持相同的高度;原因是我创建了一个元素 SlideUp,然后使用新数据进行 SlideDown,但这使得浏览器窗口在 SlideUp 开始时向上滚动到顶部,因此变得相当烦人,尤其是在低分辨率下。
最佳答案
您可以简单地获取父级的高度并通过 JQuery 将其设置为固定高度,就像我在 JSFiddle 上制作的示例一样:
$(document).ready(function() {
$('input#slideup').click(function() {
//Fix the current height of the parent container
$('div.parent').css({ 'height' : ($('div.parent').height())});
//Slide up and add new content to the div
$('div#slider').slideUp('slow', function() {
$('div#slider').html("New content!<br />New content!");
});
//Slide down again and watch how the parent container didn't move!
$('div#slider').slideDown();
});
});
关于Jquery/CSS - 使用slideUp()时使容器元素保持相同的高度;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832321/