Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cicle backGroung img #5

Open
DoctorHeavy opened this issue May 4, 2023 · 0 comments
Open

Cicle backGroung img #5

DoctorHeavy opened this issue May 4, 2023 · 0 comments

Comments

@DoctorHeavy
Copy link

DoctorHeavy commented May 4, 2023

I try to allow the background img to change every 3 min but fail

case "bgImage":
      const imagePaths = getImagePathsFromDirectory('images\\');
      let currentImageIndex = 0;

      document.body.style.backgroundImage = `url('${imagePaths[currentImageIndex].replace(/\\/g, "/")}')`;

      setInterval(function() {
        currentImageIndex = (currentImageIndex + 1) % imagePaths.length;
        document.body.style.backgroundImage = `url('${imagePaths[currentImageIndex].replace(/\\/g, "/")}}')`;
      }, 3 * 60 * 1000);
      break`
      
function getImagePathsFromDirectory(directoryPath) {
  const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif'];
  const imagePaths = [];

  const directoryReader = new FileReader();
  directoryReader.readAsArrayBuffer(new Blob([directoryPath], { type: "text/plain" }));
  directoryReader.onloadend = function() {
    const entries = directoryReader.result;
    for (let i = 0; i < entries.length; i++) {
      const entry = entries[i];
      const fileExtension = entry.name.split('.').pop().toLowerCase();
      if (imageExtensions.includes('.' + fileExtension)) {
        imagePaths.push(entry.fullPath);
      }
    }
  };

  return imagePaths;
}

pls send feed back on my errors so i can improve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant