Devi
Devi

Reputation: 61

Jquery - Delay on css for preloader not working

I was wondering why the last line $('body').delay(500).css({'overflow-y':'auto'}); does not delay the change of the css of the body. It is for my preloader. I am very new with Javascript/jquery. Hope someone can help me out. If you got any other tips to improve the script please feel free to do so!

$(window).on('load', function() {
  $('#preloader svg').fadeOut(200);
  $('#preloader-container').delay(200).fadeOut(500,'linear'); 
  $('body').delay(500).css({'overflow-y':'auto'});
})

Upvotes: 1

Views: 39

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337580

The issue is because css() does not use the fx queue, so delay() has no effect on it.

The simple fix is to use a timeout instead:

setTimeout(function() {
  $('body').css('overflow-y', 'auto');
}, 500);

Upvotes: 2

Related Questions