Embark on a coding adventure! Follow our guide to build Modern Loading using HTML, CSS, and JavaScript. Unleash your creativity in web development.
Modern loading using JavaScript involves employing asynchronous techniques such as Promises, async/await, or the fetch API to efficiently fetch resources like data, images, or scripts from servers without blocking the main execution thread, ensuring a smooth and responsive user experience.
Source Code
Step 1 (HTML Code):
1- `<div class="circle">`: This is a `<div>` element with the class attribute set to "circle". It likely represents a circular element, such as a progress circle or similar.
2- `<p class="count">`: Inside the `<div>` element, there's a `<p>` element with the class attribute set to "count". This `<p>` element likely contains the text content related to the count or percentage displayed within the circle.
3- `<span class="percent">50</span>`: Inside the `<p>` element, there's a `<span>` element with the class attribute set to "percent". This `<span>` element likely contains the actual numerical value (50 in this case) that is being displayed as a percentage.
4- `%`: This is just a simple text content that follows the `<span>` element, likely to represent the percentage symbol. It's inside the `<p>` element.
So, altogether, this HTML structure represents a circular element with a count or percentage displayed inside it. In this example, it's displaying "50%".
Step 2 (CSS Code):
Explanation:
1- The `body` rule sets the body's height to 100% of the viewport height, centers its content both horizontally and vertically, and sets the background color to dark gray (`#232323`) with white text color.
2- The `.circle` class styles the circular element with a gradient background, adds a box shadow to create a 3D effect, and applies a rotation animation (`spin`) to continuously rotate the circle.
3- The `.count` class creates a smaller inner circle for displaying the percentage text, sets its position to absolute, and applies an inset box shadow and a reverse rotation animation to create a contrasting effect.
4- The `.percent` class styles the percentage text with a large font size and a sans-serif font family.
Step 3 (JavaScript Code):
1- `$percent` and `$circle`:
- Define variables `$percent` and `$circle` to target HTML elements with the classes `.percent` and `.circle`, respectively.
2- `load`:
- Define a variable `load` to track the loading percentage.
3- `update()`:
- The `update()` function updates the `load` value and the displayed loading percentage inside the `.percent` element.
- It increments the `load` value by either 0 or 1 using the expression `load += load < 100`.
- Update the content of the `.percent` element to display the new value of `load`.
- Update the background of the `.circle` element using `conic-gradient` to represent the new loading percentage.
4- `setInterval(update, 150)`:
- It repeatedly executes the `update()` function every 150 milliseconds to continuously update the loading progress.
Source Code: Download Files
Final Output:
Conclusion:
In conclusion, creating a modern loading mechanism using JavaScript involves employing asynchronous techniques such as Promises, async/await, or the fetch API to efficiently fetch resources from servers without blocking the main execution thread. Additionally, styling techniques like CSS animations, transitions, and gradients can be used to enhance the visual appeal of the loading indicator. By combining these techniques, developers can create loading experiences that are both smooth and visually engaging, ensuring a positive user experience on modern web applications.