Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This will look at all elements of class sel, check out their 'score' attributes, and set the background color accordingly (lightest = score 0, darkest = score 100)
- // Individual element looks like this: <div class='sel otherClass' score=50'>Content</div>
- $('.sel').css('background-color',function(){
- var how = $(this).attr('score');
- if(how>100 || how<0) how=100;
- how = how/2;
- how = 100-how;
- return "hsl("+180+","+50+"%,"+how+"%)";
- });
- // If you have separately-defined scale in a .css, eg:
- // .scale40{ background-color:hsl(180,50%,80%); }
- // .scale39{ background-color:hsl(180,50%,80.5%); }
- // Then can use this:
- $('.sel').addClass(function(){
- return 'scale'+$(this).attr('score');
- });
Advertisement
Add Comment
Please, Sign In to add comment