Skip to main content

Posts

Showing posts with the label web UI

How to Rotate Your Web Page Background at Radom

How to Rotate Your Web Page Background at Random Problem: I want my web page background image to change every time the page is loaded by picking an image at random. The images in this solution are all prepared in advance. They are all named live#.jpg where "#" is a number between 1 and whatever the number of images you have.  Hence they are named: live1.jpg live2.jpg live3.jpg ........ The naming system simplifies the script that will be used to load the images. The approach adopted is a three-step algorithm: Create an array of the file names for these image files in a certain folder. In my case, the folder is called "slides". Count the number of files . There are possibilities of counting sub-directories and . and .. if not careful. In this solution, we ensure no subdirectories are in the target folder and do a little arithmetic to eliminate the .. and .. folders. Generate a random number based on the number of files in the target folder a...