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 !!
YannickWelcome to the forums.<style type="text/css">
/*<![CDATA[*/
html, body {
background-attachment: fixed;
}
/*]]>*/
</style>Further, I've moved this to CSS as it isn't really JavaScript related.OK thank you It works perfectly !!!
//<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 !!
YannickWelcome to the forums.<style type="text/css">
/*<![CDATA[*/
html, body {
background-attachment: fixed;
}
/*]]>*/
</style>Further, I've moved this to CSS as it isn't really JavaScript related.OK thank you It works perfectly !!!