Friday, 15 June 2012

css - Change HTML background image on click -



css - Change HTML background image on click -

how alter background image on click have code

html { background: url(img01.jpg) no-repeat center center fixed; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; }

i have 5 div's . 4of them hidden . when click on button show's me next div , hide previous . when show me next div want show new background image under div. how :(

<div id='2' style="display: none;"> <input type='button' div_funkcija(2);" value="sehr-gut"> <input type='button' div_funkcija(2);" value="gut"> <input type='button' div_funkcija(2);" value="befriedigend"> <input type='button' div_funkcija(2);" value="ausreichend"> <input type='button' div_funkcija(2);" value="mangelhaft"> </div>

and script

function div_funkcija($div) { document.getelementbyid($div).style.display='none'; document.getelementbyid($div+1).style.display='block'; }

now when open's new div how show on body or html background new image.

function div_funkcija($div) { document.getelementbyid($div).style.display='none'; document.getelementbyid($div+1).style.display='block'; document.getelementsbytagname('html')[0].style.backgroundimage='url(newimage.jpg) no-repeat center center fixed'; }

or can give html tag id , utilize document.getelementbyid. additoinal suggestion, don't style html tag, reference body.

html css image background

No comments:

Post a Comment