Pezmc
06-08-2008, 09:15 PM
Does anyone know a faster and less repetative way to do this? It is for whether effects on a game.
Here is my code:
function Night(css) {
if (hora >= 21 && hora <= 24 || hora >= 0 && hora <= 5) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Sunrise(css) {
if ( hora >= 6 && hora <= 9 ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Sunset(css) {
if ( hora >= 18 && hora <= 20 ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Rain(css) {
if ( hora >= rainstarttime && hora <= rainendtime ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Fog(css) {
if ( hora >= fogstarttime && hora <= fogendtime) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
an example bit of the function being used is:
Night('#city #container .phase2, #city #container .phase3 { background-image:url('+webadress+'Night/city_phase2.jpg);}');
thanks
Here is my code:
function Night(css) {
if (hora >= 21 && hora <= 24 || hora >= 0 && hora <= 5) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Sunrise(css) {
if ( hora >= 6 && hora <= 9 ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Sunset(css) {
if ( hora >= 18 && hora <= 20 ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Rain(css) {
if ( hora >= rainstarttime && hora <= rainendtime ) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
function Fog(css) {
if ( hora >= fogstarttime && hora <= fogendtime) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
};
};
an example bit of the function being used is:
Night('#city #container .phase2, #city #container .phase3 { background-image:url('+webadress+'Night/city_phase2.jpg);}');
thanks