Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand div with animation

I have a div that is receiving content from an ajax call. Right now I am just doing this in the ajax callback handler:

function searchCallback(html) { $("#divSearchResults").html(html); }

This makes the content "pop" onto the page, and it's very abrupt. Is there a way to make the div gracefully resize, like the .slideToggle() method does?

like image 814
Jon Tackabury Avatar asked Mar 01 '23 21:03

Jon Tackabury


2 Answers

Make sure its hidden, then add the content and just slide it in.

$("#divSearchResults").hide();
$("#divSearchResults").html(html);
$("#divSearchResults").slideDown();

Or you could fade it in:

$("#divSearchResults").fadeIn();

To make sure your page doesn't "explode" when the content appears, make sure the div is hidden to being with. Also, make sure that once content is added, the page looks fine.

like image 89
John B Avatar answered Mar 12 '23 07:03

John B


You could have it hidden to begin with. Then insert the html and when that function is done, do a show effect on it. (like your slideToggle)

like image 36
Ólafur Waage Avatar answered Mar 12 '23 08:03

Ólafur Waage