Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
### Improvements Made:

1. **Consistent Variable Naming**: Changed `int` to `intervalId` for clarity.
2. **Increment Operator**: Used `load++` instead of `load += 1` for simplicity.
3. **Function and Variable Placement**: Moved `scale` function above the `setInterval` for logical flow.
4. **Comments**: Added comments for better understanding and maintainability.
5. **Spacing and Formatting**: Improved spacing and formatting for readability.

These changes should make the code more readable and maintainable without altering its functionality.
  • Loading branch information
Imran-imtiaz48 authored Jul 9, 2024
1 parent 291880a commit 29ae11a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Source-Code/BluringImage/script.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
/* eslint-disable*/
// Disable ESLint for the entire file
/* eslint-disable */

// Select DOM elements
const loadingText = document.querySelector(".loading-text");
const bg = document.querySelector(".bg");

let load = 0;

// Function to update the loading state and apply styles
const blurring = () => {
load += 1;
load++;
if (load > 99) {
clearInterval(int);
clearInterval(intervalId);
}
loadingText.innerText = `${load}%`;
loadingText.style.opacity = scale(load, 0, 100, 1, 0);
bg.style.filter = `blur(${scale(load, 0, 100, 30, 0)}px)`;
};

const int = setInterval(blurring, 20);
const scale = (num, in_min, in_max, out_min, out_max) => {
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min;
// Start the interval to run the blurring function every 20ms
const intervalId = setInterval(blurring, 20);

// Utility function to scale a number from one range to another
const scale = (num, inMin, inMax, outMin, outMax) => {
return ((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
};

0 comments on commit 29ae11a

Please sign in to comment.