The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
How do I change the .body background color with Javascript?
As per title. I would like to add an option to let users change the style's .body background color in their usercp. And it should be saved in their options, so they see that color until they change it again.
|
#2
|
|||
|
|||
Hi,
i've been looking at something like this myself, here is a very basic example 1st you need to save this code as a Javascript so copy it to your notepad and save it as "Backcolor.js" Code:
function change_it() { if (document.getElementById && document.createTextNode) { var new_color = ""; var color_sel = document.getElementById("change_bg").value; color_sel *= 1; switch (color_sel) { case 0 : window.alert("Please select a color."); return false; case 1 : new_color = "#FFFF00"; break; case 2 : new_color = "#3333FF"; break; case 3 : new_color = "#009900"; break; } document.body.style.backgroundColor= new_color; return false; } } Then enter the code below, between the <body> and </body> tags where you want the select box and button to appear, ideally in the footer or header templates Code:
<form action="#" onsubmit="return change_it();"> <select name="change_bg" id="change_bg"> <option selected="selected" value="0">Select Background</option> <option value="1">Yellow</option> <option value="2">Blue</option> <option value="3">Green</option> </select> <input type="submit" value="Change Color" /> </form> <script type="text/javascript" src="backcolor.js"></script> i've done this very basic, but you can change the colors in the backcolor.js file just change the case 1, 2 and 3 options with a new hex color #FFFFFF You can get a nice selection of hexcolors here http://www.december.com/html/spec/colorsafe.html This is what you get, Mind you it won't work well on my forum as its fluid, but it'll work well with fixed forums Remember you can change these colors, I've just done 3 as an example, But you can add as many as you want and with millions of combinations by using a color Hex chart. Have Fun To see the new template edit in the mods forum https://vborg.vbsupport.ru/showthread.php?t=200096 |
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|