Also, codeacademy.com is fantastic.
Take a squizz at their source code and you'll see how Habbox does it.
and to get their coloursPHP Code:
//redandgreenfunction alternatingColours(selector, rainbowcolours)
{
var currentcolor = 0;
var amountinarray = rainbowcolours.length;
$(selector).each(function(){
var letters = $(this).html().split('');
$(this).html('');
for(var i in letters)
{
if(letters[i] != ' ')
{
if(letters[i].toString().search('unction') == -1)
$(this).append('<span style="font-weight: bold; text-decoration: none; color: #' + rainbowcolours[currentcolor] + ';">' + letters[i] + '</span>');
currentcolor++;
if(currentcolor == amountinarray) currentcolor = 0;
}else{
$(this).append(' ');
}
}
});
}
and then they set the class of the span they want to change colours to that name (redandgreen)PHP Code:
$(document).ready(function(){
alternatingColours('.redandgreen',Array('CB150B','3C8D0D'));//redandgreen});
Want to hide these adverts? Register an account for free!