alienphp Posted August 5 Share Posted August 5 Hello, I need your help. Im trying run code after few seconds (5s). I tryed sleep() function, but the sleep function stop whole page for 5seconds. I explain what to you what Im trying. I have loading bar, loading for 5s. for example: <div class="loadingbar" style="--width: 10" data-label="Loading..."></div> <?php // After 5s I need start this code and hide loading bar in this page, without redirecting. echo "sucesfully loaded" Is it possible, please? If yes, how to do? If hiding the loading bar is not possible, how to just wait 5s for the code start? Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/322877-php-start-code-after-few-seconds/ Share on other sites More sharing options...
Barand Posted August 5 Share Posted August 5 Once your page hits the browser there is nothing php can do. Any further client-side processing will require javascript. When page has loaded, set a timer ( see setTimeout() ) to initiate a process which hides your loading bar. 1 Quote Link to comment https://forums.phpfreaks.com/topic/322877-php-start-code-after-few-seconds/#findComment-1632082 Share on other sites More sharing options...
jodunno Posted August 6 Share Posted August 6 adding to Sir Barand's statements: if you cannot figure out the JavaScript code or you're too lazy to try, then you could use CSS 3 with animations which will show and hide a span inside your div. I wonder, exactly how do you plan to fit the words "Successfully Loaded" into a 10 pixel div? Quote Link to comment https://forums.phpfreaks.com/topic/322877-php-start-code-after-few-seconds/#findComment-1632106 Share on other sites More sharing options...
jodunno Posted August 24 Share Posted August 24 so you haven't replied in weeks . I assume based upon your post that you just want to remove the loading bar and display successfully loaded message, yes? <html> <head> <title>5 sec div</title> <style> @keyframes loading { from { opacity: 1; } to { opacity: 1; visibility: hidden; } } @keyframes loaded { from {opacity: 0;} to {opacity: 0;} } .loadingbar { max-width: 100px; border: solid 1px #c0c0c0; } .loading { animation: 5s linear loading; opacity: 0; } .loaded { animation: 5s linear loaded; } .load { position: absolute; top: 0 px; left: 0 px; padding: 8 px; } </style> </head> <body> <div class="load loading loadingbar">Loading ...</div> <div class="load loaded">Successfully Loaded</div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/322877-php-start-code-after-few-seconds/#findComment-1633497 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.