Skip to content

Cicle backGroung img #5

Description

@DoctorHeavy

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions