Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load javascript after 5 seconds after page has loaded?

I have tried the following:

<body id="myBody" onload = "setTimeout('a()', 5000)" / >

Is this the correct method? The reason why I want to do this is because I have my entire website animating in (such as fade ins) on page load. Having my javascript only makes the animation unsmooth.

Any feedback appreciated.

like image 292
The Javascript Noob Avatar asked Oct 19 '25 04:10

The Javascript Noob


1 Answers

This code will work. Just set your time in milliseconds and write your JS code on loadAfterTime function:

<script>
 window.onload = function(){
   setTimeout(loadAfterTime, 5000)
};


function loadAfterTime() { 
// code you need to execute goes here. 
}
</script>
like image 89
Jakir Hossain Avatar answered Oct 21 '25 17:10

Jakir Hossain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!