简体   繁体   中英

jQuery: Hide div when page is loading and show div with transition

I'm currently working on a project and I'm having problems with my hero section text jQuery. The scenario is when the page is loading, the text should not be visible but when it's loaded, the text will show.

Here is my CSS code:

.hero_description{
  visibility: hidden;
}

and here is my jQuery:

jQuery(function($) {
    jQuery('.hero_description').show();
},2000);

The problem is, it's not showing the proper transition as it renders first at the top, and once its other CSS styles are rendered it goes to its proper place in the middle.

If you want it to show with a transition, you'll need to use fadeIn() instead of show() . Also make sure to hide() the element first to prevent any flickering.

 jQuery('.hero_description').hide().fadeIn(2000);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> content above <div class="hero_description">DESCRIPTION HERE</div> content below

its very simple

$('.hero_description').fadeIn(2000);

JS Fiddle

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