Reputation: 11448
I was wondering if there was a way to make the parent container keep the same height when using slideup(); The reason for this is that I make an element slideUp, then slideDown with new data but this makes the browser window scroll up to the top when the slideUp begins, so it gets rather annoying, especially on low resolutions.
Upvotes: 1
Views: 2348
Reputation: 7223
You can simply grab the parent's height and set it to a fixed one through JQuery like in the example I made on 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();
});
});
Upvotes: 6
Reputation: 987
You can set the parent's height in css anytime before hiding the child element: EDIT: just set the height directly with jQuery:
var parent = $('#parent');
parent.height(parent.height());
Upvotes: 0