-2

I would like to create a site similar to http://www.tomford.com/ but in HTML.

the problem is how do I create a background where images

  • change automatically background
  • user clicks a icon to change background
  • done in css or java script

What I have done:

<body style="background: url(url of image) repeat-x repeat-y center"></body>
mishik
  • 9,973
  • 9
  • 45
  • 67
LeRoy
  • 4,189
  • 2
  • 35
  • 46

3 Answers3

2

You can do this by either setting the background image via jQuery/JS or by setting a class on the item and having the background images defined in the CSS.

To do the first, you can read through this thread: change background image in body

Basically

$('.icon').click(function() {
    $('body').css('background-image', 'url(../images/backgrounds/header-top.jpg)');
});

OR

$('.icon').click(function() {
    $('body').removeClass().addClass('bg-1'); 
    //removes all classes, then adds the new class
});

Where .icon is whatever thing you want to click to trigger the change.

You would then just declare a background for .bg1 in your CSS.

Community
  • 1
  • 1
robooneus
  • 1,344
  • 8
  • 10
1

you can do it in jquery this way

JS CODE:

var url="http://......."
$('...').on('click',function(){ 
    $('body').css('background:',url);
});

Note: the click event can be called based on specific selector(class,id or tag name)

Happy Coding :)

dreamweiver
  • 6,002
  • 2
  • 24
  • 39
0

You can do it via CSS3 transitions, like shown here.

Daniel Schmidt
  • 11,605
  • 5
  • 38
  • 70