Using jQuery To Animate Inserting Text Into Div

删除回忆录丶 提交于 2019-12-06 11:57:54

If you want to truly animate the text in, you would have to slowly append the text, one letter at a time. You can get a similar effect by using what others have mentioned already, .slideDown()

http://jsfiddle.net/rkw79/fCAVp/

$("#my-div")
    .hide()
    .html("some new really long string of text ...")
    .slideDown('slow');

Maybe you could use a combination of the css attributes overflow:hidden; height:... and jQuery's slideDown() function.

Insert the text into a fixed-height div, determine the new height and animate it.

The answer is very simple: adjust the height automatically and very slowly as you drop more text in the div:

$('#thedivid').append('<p>'+newtextbeingadded+'</p>').animate( { 'height':'auto' },5000 );

That should, probably, do the trick. You might need to adjust the 5000 accordingly.

Also, chances are that a vertical scroll bar would appear so you would want to make the 'thedivid' with overflow:hidden;

Good luck!

you can use slideDown() and slideUp().

something like this:

$("#my-div").slideUp('slow', function() { $("#my-div").html("some new really long string of text which makes the div height increase."); }).slideDown('slow');

Edit:

you may want to increase the div height smoothly, to do so you can use animate() and height() this way.

I also created a FadeIn sample.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!