The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

Randomize name color

View previous topic View next topic Go down

Solved Randomize name color

Post by Derp-chan on 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
Forumember

Female Posts : 27
Reputation : 1
Language : English

http://forumthingwhatever.forumotion.com/

Back to top Go down

Solved Re: Randomize name color

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

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

Ace 1
Helper
Helper

Male Posts : 767
Reputation : 51
Language : English - French?
Location : Druid Hill Park

http://help.forumotion.com

Back to top Go down

Solved Re: Randomize name color

Post by Ange Tuteur on 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
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Randomize name color

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

That worked, thank you!

Derp-chan
Forumember

Female Posts : 27
Reputation : 1
Language : English

http://forumthingwhatever.forumotion.com/

Back to top Go down

Solved Re: Randomize name color

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

You're welcome ! Smile

Topic archived

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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