does anyone know how to make a website that has a background that changes every time you go to the home page just like the tumblr home page.

Recommended Answers

All 2 Replies

There are variety of ways to accomplish this, but a simple solution may include assinging a random background image to the page every time the page is loaded.

This would involve storing the path of the images in a javascript array and generating a random number within the length of the array. This random number will be used for selecting the array index that holds the picture for the background image.

Here's a demo: http://itg.somee.com/dw/dw-466413/

The script may look something like this...

<script>
  var backImg = [
      "image1.jpg",
      "image2.jpg",
      "image3.jpg"
  ];

var rnd = Math.floor(Math.random() * backImg.length);   

if (document.body){
   document.body.style.backgroundImage = 'url(' + backImg[rnd] + ')';
}
</script>

Why dont you give it a try, post some of your own code and see if you can build upon the sample above..

try aimated gif or use refresh component and serve different version of the page. but best is to use javascript or php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.