katiek

_.js faded/cut-off text template

Mar 24th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Underscore.js template for faded/cutoff text
  2. // usage: _.template($('#textFader').text())({'content' : WHATEV, 'max' : 25, 'colors' : 'grayscale'});
  3.  
  4. <script id="textFader" type="text/html"><% if(colors=='grayscale') colors=new Array('rgb(0, 0, 0)','rgb(99, 99, 99)','rgb(189, 189, 189)','rgb(240, 240, 240)'); fade = max-colors.length+1; cutoff=content.length<=max?max:fade; for(var i = 0; i < cutoff; i++){ %><span style='color:<%= colors[0] %>'><%= content.substr(i,1) %></span><% } %><% for(var i = cutoff; i < max; i++){ %><span style='color:<%= colors[i-fade+1] %>'><%= content.substr(i,1) %></span><% } %></script>
  5. </head>
Advertisement
Add Comment
Please, Sign In to add comment