This is a simple way to do it without directly using setTimeout. Just use the jquery .delay()
which works with .fadeIn()
, since your body is already visible, it won't do anything, since it's already visible, but then after the delay it calls the fade in function, and then it calls the threeSecondDelayFunction which executes.
$(document).ready(function() {
function threeSecondDelayFunction() {
$('body').addClass('js');
var $menu = $('#menu'),
$menulink = $('.menu-link');
$menulink.click(function() {
$menulink.toggleClass('active');
$menu.toggleClass('active');
return false;
});
}
$('body').delay(3000).fadeIn(0, function() { // delays for 3 seconds which is equal to 3000 miliseconds , then calls the fadeIn function which doesn't do anything in itself, but we call the function that includes the code you want delayed after the delay and fadeIn functions complete
threeSecondDelayFunction();
});
});