Jquery display: name

Asked

Viewed 195 times

-5

I need to put one display: nome to block the class soon, but, the way I did, it is not working. I managed to put a opacity:0 but the display didn’t pick up.

$(document).ready(function(){
    $(".logo").animate({display: 'nome'}, 0);
});
  • 6

    'nome' != 'none'

2 answers

9


The error is typing and usage.

Replace with:

<script>
    $(document).ready(function() {

        $('.logo').css('display', 'none');

    });
</script>

The method jQuery.fn.animate does not work for the property display because it does not exist in the step. And you put "name" in the mail of none.

You can create a transition for the element to disappear using jQuery.fn.fadeOut in this way:

$('.logo').fadeOut(400);

400 being the duration of the effect.

To make it appear just use jQuery.fn.fadeIn likewise.

I believe that already resolves.

  • 1

    OK got it perfectly, but how do I use a Duration there ? that’s kind of the Transition if you know what I mean

  • 1

    When filling Duration you need an animation that makes the transition effect and at the end give None display, you can check it manually, but jQuery has some functions ready. You can use in this case $('.logo').fadeOut(400); this function makes disappear and 400 is the duration (To appear use "fadein").

  • 1

    I got vlw diego =D

  • @brasofilo will do it, thank you.

6

You cannot animate the display property. Before changing to display none (that you wrote wrong), you must animate another property whatever makes the element disappear:

  • width or height: animate to 0;

  • opacity: animate until full transparency (note that this will cause an undesirable effect as the space will continue occupied during the animation)

Then after these animations, you can set the None display.

Example:

$('.logo').animate({
     width: 0
   },
   {
     duration: 5000,
     complete: function(){
        $('.logo').hide();
    }
});
  • 1

    I got it Miguel =D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.