I'm currently working on a project where I need to display random background images when the body loads. To achieve this, I've created a function. However, I'm facing an issue where the images are filling up the entire page, making it very long. I want them to be displayed only within the height and width of the body. Here's the code snippet I have so far:
var body = document.body;
var html = document.documentElement;
var bodyHeight = Math.floor(Math.min(body.scrollHeight));
var htmlHeight = Math.floor(Math.min(html.scrollHeight));
var height = Math.max(bodyHeight, htmlHeight);
for(i=0; i<height; i++){
var images = [];
// Add image URLs to the array here
index = Math.floor(Math.random() * images.length);
document.write(images[index]);
}