简体   繁体   English

如何使 addEventListener 同步

[英]How to make addEventListener sync

when window loads div with a class preload doesnt disappear with transition 0.5s;当窗口加载带有类预加载的 div 时,过渡 0.5s 不会消失; it disappears immediately.它立即消失。 I want to first disappear with transition 0.5s then add display none我想先用过渡 0.5s 消失然后添加 display none

window.addEventListener('load', () => {
      $('.preload').css({
         'opacity': '0',
         'transition': '0.5s'
      });
   });
   $('.preload').css('display': 'none');

I think this is the shortest way to achieve that.我认为这是实现这一目标的最短途径。 fadeOut is a jquery method, which creates an animation, for fade effect, and sets display to none , when the element gets faded completely. fadeOut是一个 jquery 方法,它创建一个动画,用于淡入淡出效果,并在元素完全淡化时将display设置为none The parameter is the time for transition in milliseconds .该参数是以milliseconds transition时间。

Check fadeOut here : fadeOut在这里检查fadeOutfadeOut

 $(window).on('load', () => { $('.preload').fadeOut(500); });
 html, body{ margin: 0; } .preload { height: 200px; width: 100vw; background: red; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="preload"></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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