Follow @josdirksen Tweet to @josdirksen Tweet

Random background from Colourlovers

This page uses the API from the COLOURlovers website to set a random background based on the top patterns. This is done by taking the following simple steps:

All you have to do this is (for more info see this article on http://www.smartjava.org):

// We retrieve a set of the 50 top backgrounds
$.getJSON('http://www.colourlovers.com/api/patterns/top?jsonCallback=?&numResults=50',
          function(data) {

  // we randomly select one of the elements
  var element = data[Math.floor(Math.random()*50)];

  // we update the body background with the url
  $('body').css({
    "background-image": "url("+ element.imageUrl +")"
  });
});