I use jquery on the pages of the site, connecting via cdn:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 

The problem is that when using the function hide, show, toggle, the element disappears or appears not simply, but as if folding or unfolding, which does not suit me. I would like to work as fadeIn and fadeOut.

  • if you want to work as fadeIn then use it. When you call hide with no parameters, there is no animation, otherwise the following behavior is documented: animates the width, height, and opacity of the matched elements simultaneously . - teran

1 answer 1

The functions hide, show, toggle work incorrectly when using jquery

Functions work exactly as described in the documentation:

the matched elements simultaneously

That is, animate the width, height and transparency of the element. And if the parameters are not transferred to the function, then there is no animation at all, the blocks are simply hidden / shown.

If you need to hide elements using only transparency, use the corresponding functions that you mention yourself: fadeIn() , fadeOut() , fadeToggle() .

Attempts to achieve the same behavior from other functions are meaningless. At least this meaning is not described in your question. If for some reason you cannot use these functions, then add your question, because He is not clear in the current wording.

  • Fade functions are too slow. How to make just instant hiding / showing items through transparency? - Artur Han
  • one
    @ArturHan how do you imagine instant, and transparency? here either the duration is 0, and there are no animations at all, or some duration is set. There are two preset parameters - fast (200ms) and slow (600ms), the default duration is 400ms. Use a preset, or set the desired duration in the parameters ( fadeIn( 100 ); - two times faster than fast, for example.) - teran
  • And how to remove the animation from hide, so that the element simply disappears? - Artur Han
  • @ArturHan when called without parameters, there should not be any animation. - teran 4:16 pm