add loadin animation while load the page give me new full updated code
Certainly! Below is the complete updated HTML code with a loading animation added. The loading screen will display a spinner while the page is loading and will smoothly disappear once the page has fully loaded.
Key Additions:
Loading Screen HTML:
A <div> with the ID loading-screen is added at the beginning of the <body>. This div covers the entire viewport and centers the loader.
Loading Screen Styles:
Tailwind CSS classes are used to style the loading screen, ensuring it covers the full screen and centers the loader both vertically and horizontally.
Loader Component:
Utilizes DaisyUI's built-in loader component for a consistent and visually appealing spinner.
JavaScript for Loading Screen:
A script is added at the end of the <body> to listen for the window.onload event. Once the page is fully loaded, it adds a fade-out class to the loading screen, triggering a fade-out animation, and then removes the loading screen from the DOM.
Fade-Out Animation:
Custom CSS is added to define the fadeOut keyframes and apply the animation to the loading screen when the fade-out class is added.
Positioned fixed to cover the entire viewport (fixed inset-0).
Uses Flexbox to center the loader both vertically and horizontally (flex items-center justify-center).
Sets a high z-index (z-50) to ensure it's above all other content.
Includes a spinner and a loading message.
Loader Styling:
The spinner uses Tailwind CSS classes to create a rounded, animated spinner. You can customize the size and colors as needed.
The loading message (جارٍ التحميل...) provides feedback to users that the page is loading.
Fade-Out Animation:
Defined using CSS @keyframes fadeOut which gradually changes the opacity from 1 to 0 and hides the element.
The .fade-out class applies this animation over 0.5 seconds.
JavaScript Logic:
Theme Toggle:
Remains unchanged from your original code, handling the dark and light theme toggling.
Loading Screen:
Listens for the window.onload event to ensure the entire page, including images and other resources, has loaded.
Once loaded, it adds the fade-out class to initiate the fade-out animation.
After the animation completes (animationend event), it removes the loading screen from the DOM to free up resources.
Customization Tips:
Loader Size and Color:
Adjust the h-24 w-24 classes to change the size of the spinner.
Modify the border-8 border-t-8 border-gray-200 classes to change the spinner's thickness and color. For example, border-primary can be used to match your primary theme color.
Loading Message:
Feel free to update the loading message text to better fit your application's context or translate it as needed.
Animation Duration:
The fade-out animation duration is set to 0.5s. You can increase or decrease this value in the .fade-out class for a faster or slower transition.
This integration ensures that users see a smooth loading animation while the page content is being fetched and rendered, enhancing the overall user experience.