The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Randomize name color

3 posters

Go down

Solved Randomize name color

Post by Derp-chan August 17th 2015, 2:24 am

I know it's possible to make a color change with each refresh using JS, but is there any way to apply this to a username maybe?



Last edited by Derp-chan on August 17th 2015, 5:03 pm; edited 1 time in total
Derp-chan
Derp-chan
Forumember

Female Posts : 29
Reputation : 1
Language : English

http://forumthingwhatever.forumotion.com/

Back to top Go down

Solved Re: Randomize name color

Post by Ace 1 August 17th 2015, 3:13 am

if the user is in a group. then its close to impossible without heavy coding.
Ace 1
Ace 1
Helper
Helper

Male Posts : 843
Reputation : 64
Language : English - French?
Location : Druid Hill Park

https://help.forumotion.com

Back to top Go down

Solved Re: Randomize name color

Post by Ange Tuteur August 17th 2015, 10:15 am

It's possible, you'll just need to use JavaScript to apply a random class. For example :

Go to Modules > JavaScript codes management > New script

Placement : In all the pages
Code:
$(function() {
  var users = {
    'u1' : ['style_1', 'style_2', 'style_3'],
    'u2' : ['style_3'],
    'u3' : ['style_1', 'style_2']
  },
  a = document.getElementsByTagName('A'), i = 0, j = a.length, k;
 
  for (; i < j; i++) for (k in users) if ($(a[i]).attr('href') == '/' + k) a[i].className += ' ' + users[k][Math.floor(Math.random() * users[k].length)]
});

The script above will apply a random class to users 1 and 3, whereas user 2 is stuck with .style_3. The strings in the arrays are just random classnames for the example. You can change them to whatever you want.

Then you just have to write some styles for your classnames.. Smile
Code:
.style_1, .style_1 > span { color:red !important }
.style_2, .style_2 > span { color:green !important }
.style_3, .style_3 > span { color:blue !important }
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Solved Re: Randomize name color

Post by Derp-chan August 17th 2015, 5:02 pm

That worked, thank you!
Derp-chan
Derp-chan
Forumember

Female Posts : 29
Reputation : 1
Language : English

http://forumthingwhatever.forumotion.com/

Back to top Go down

Solved Re: Randomize name color

Post by Ange Tuteur August 17th 2015, 5:05 pm

You're welcome ! Smile

Topic archived
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum