简体   繁体   中英

How to add a fade-in effect in jQuery text

How to add a fade-in effect when the data is returned to the #results div?

$('#results').html(data);

I tried

$('#results').html(data).fadeIn('slow');

but it doesn't seem to work

My code

        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('mailme.php', $("#myform").serialize(), function(data) {
                $('#results').html(data).fadeIn('slow');
            });
        }

您必须先隐藏div。

$('#results').hide().html(data).fadeIn('slow');

这可能会解决问题。

$('#results').css('display', 'none').html(data).fadeIn('slow');

you have to hide element firstly when you are working with "fadeIn".

here is a example, I believe you will understand after trying and editing that:

<img style="display: none;" id="google" src="http://www.google.com.tr/images/srpr/logo3w.png" alt="" />

<script>
    $(document).ready(function() {
        $('#google').fadeIn(1200,function(){});
    });
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM