Faster and neater way to do this?
Posted: Sun Jun 08, 2008 3:20 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:
an example bit of the function being used is:
thanks
Here is my code:
Code: Select all
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);
};
};Code: Select all
Night('#city #container .phase2, #city #container .phase3 { background-image:url('+webadress+'Night/city_phase2.jpg);}');