/    Sign up×
Community /Pin to ProfileBookmark

java script background question

Hi guys, i have question about a simple javascript that i made:

//<SCRIPT LANGUAGE=”JavaScript” TYPE=”text/javascript”>
//<![CDATA[
function pageChange(){

var today=new Date();
var hour=today.getHours();
var year=today.getFullYear();
var month=today.getMonth();
var day=today.getDate();

switch (year) {
case 2004:
switch (month) {
case 3:
switch (day) {
case 11:
document.body.background = “images/BackgroundEaster_03.jpg”;
break;
case 12:
document.body.background = “images/BackgroundEaster_03.jpg”;
break;
default:
if((hour>8) && (hour<=20)){
document.body.background = “images/Background_03.jpg”;
}
else if((hour>20) ||(hour<=8)){
document.body.background = “images/BackgroundNight_03.jpg”;
}
}
break;
default:
if((hour>8) && (hour<=20)){
document.body.background = “images/Background_03.jpg”;
}
else if((hour>20) ||(hour<=8)){
document.body.background = “images/BackgroundNight_03.jpg”;
}
}
break;
}
}
//]]>
//</SCRIPT>

As you can see the script looks at the hour of the day and changes the background of my webpage to a day-background or a night-background. But the problem is when i scroll my webpage, the background scrolls too, because it’s default. Now i need to know how to put in my javascript file how to make it that when i scroll my webpage, only the text and other contents scroll, but the background stays the way it is. Is that possible ??

Thanks in advance !!

Yannick

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@fredmvApr 27.2004 — Welcome to the forums.&lt;style type="text/css"&gt;
/*&lt;![CDATA[*/
html, body {
background-attachment: fixed;
}
/*]]&gt;*/
&lt;/style&gt;
Further, I've moved this to CSS as it isn't really JavaScript related.
Copy linkTweet thisAlerts:
@YannickauthorApr 27.2004 — OK thank you ? It works perfectly !!!
×

Success!

Help @Yannick 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.25,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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