Simple fadeIn and visibility in jQuery

后端 未结 3 1998
Happy的楠姐
Happy的楠姐 2021-02-13 13:10

I\'m trying to change the css property visibility of a div to visiblewith a jQuery .fadeIn()transition.

Here is my code :

相关标签:
3条回答
  • 2021-02-13 13:39

    You cannot animate visibility. fadein is keyed off display:none;, so that should be #test's initial state via CSS. If you need to keep the layout, you can try wrapping test in a div that specifies the height and/or width you need.

    0 讨论(0)
  • 2021-02-13 13:46

    Actually, I liked davidaam's answer. I would make a slight modification:

        $('#test').css('visibility','visible').hide().fadeIn("slow");
    
    0 讨论(0)
  • 2021-02-13 13:53

    You could also use CSS opacity combined with JQuery's fadeIn to achieve the same thing.

    Instead of using visibility in your CSS, use opacity: 0; Then use jQuery FadeTo to increase the opacity to 100%:

    $('#test').fadeTo('slow', 1);

    This will preserve positioning like visibility does, however, it's important to note that opacity: 0 responds to events such as click and keypress as well as participating in the taborder. Additionally, I've also read that a responsible use of visibility: hidden rather than display: none is better for SEO, but I'm not sure how this applies to opacity: 0.

    JSFIDDLE: http://jsfiddle.net/np6r7/15/

    0 讨论(0)
提交回复
热议问题