/    Sign up×
Community /Pin to ProfileBookmark

css background changer

Hi –
I’ve got a div which displays a background image. I’d like to find a script which changes the background used in that div each time the visitor views the page. (not a slideshow-like rotator, just a randomizer)
Can you recommend one?

Here’s the CSS:

[code]#graphic {height: 75px; width: 100%; margin: 0; padding: 0; background: url(../images/graphic-1.jpg) #fff no-repeat; display: block; text-align: center; }[/code]

Thanks,
KDLA

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@hansschmuckerAug 18.2006 — make the div id="randomizeBGdiv" ,then this should work:
<i>
</i>&lt;html&gt;&lt;head&gt;
&lt;script type="text/javascript" language="Javascript" &gt;
bgimages=new Array(
"MarketClub-Dateien/k4.gif",
"MarketClub-Dateien/k5.gif",
"MarketClub-Dateien/k6.gif"
);

<i> </i>window.onload=function(){ document.getElementById("randomizeBGdiv").style.backgroundImage="url("+bgimages[Math.floor(Math.random()*bgimages.length)]+")"; }
&lt;/script&gt;
&lt;/head&gt;
&lt;body id="randomizeBGdiv"&gt;
Hello World
&lt;/body&gt;
&lt;/html&gt;


Edit: Tested, fixed typo
Copy linkTweet thisAlerts:
@KDLAauthorAug 18.2006 — Thanks!
×

Success!

Help @KDLA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...