Is there a way to have multiple backgrounds in your CSS and allow for each user to pick their own?
This is a Hitskin.com skin preview
Install the skin • Return to the skin page
This is a Hitskin.com skin preview
Install the skin • Return to the skin page
$(function() {
var backgrounds = [
'red',
'green',
'blue',
'cyan',
'yellow',
'magenta',
'white',
'black'
], i = 0, j = backgrounds.length, c = my_getcookie('fa_background'), s = document.createElement('SELECT'), o = '<option value="">Select a background</option>';
for (; i<j; i++) o += '<option ' + ( c == 'bg-' + backgrounds[i] ? 'selected="true"' : '' ) + ' value="bg-' + backgrounds[i] + '">' + backgrounds[i] + '</option>';
s.innerHTML = o;
s.onchange = function() {
/bg-.*/.test(document.body.className) && (document.body.className = document.body.className.replace(/bg-.*/,''));
document.body.className += ' ' + this.value;
my_setcookie('fa_background', this.value);
};
document.body.appendChild(s);
document.body.className += ' ' + s.value;
});
body.bg-red { background:red }
body.bg-green { background:green }
body.bg-blue { background:blue }
body.bg-cyan { background:cyan }
body.bg-yellow { background:yellow }
body.bg-magenta { background:magenta }
body.bg-white { background:white }
body.bg-black { background:black }
body.bg-red { background:url(images/redbg.png) repeat red }
if (/\/f1-mycat/.test(window.location.pathname)) document.body.className += ' bg-locale-mycat';
body.bg-locale-mycat { background:url(images/mycat.png) repeat #FFF !important }
/* use the !important flag to override styles, namely, the bg selector backgrounds */
/* default background */
body { background:gray }
s.id = 'backgroundSelector';
#backgroundSelector {
display:block;
margin:0 auto;
}
body { background:url(IMAGE) }
Ange Tuteur wrote:You define the background style via CSS, the selector script is only for applying the classname to the body tag. So, if I wanted to display an image for the red background, I would change the value to this :
- Code:
body.bg-red { background:url(images/redbg.png) repeat red }
In answer to your other question, yes it's possible by checking either the location object or an anchor element on the page. For example ;
- Code:
if (/\/f1-mycat/.test(window.location.pathname)) document.body.className += ' bg-locale-mycat';
and css :
- Code:
body.bg-locale-mycat { background:url(images/mycat.png) repeat #FFF !important }
/* use the !important flag to override styles, namely, the bg selector backgrounds */
if (/\/f66-xwa-head-2-head/.test(window.location.pathname)) document.body.className += ' bg-f66';
body.bg-f66 { background:#FF0 }
$(function() {
if (/\/f66-xwa-head-2-head/.test(window.location.pathname)) document.body.className += ' bg-f66';
});