I have a string to change the color of each word that needs to be broken
this is my The HTML code is
& lt; Div class = "header" & gt; & Lt; Span class = "title" & gt; & Lt; Advertising & amp; Nbsp; & Lt; / Span & gt; & Lt; Span class = "title" & gt; & Lt; & Lt ;;; Weather time for free & lt; / Span & gt; & Lt; Span class = "title" & gt; & Lt; & Lt ;;; Cubitur Mile and Exposure Lets Finebus & lt; / Span & gt; & Lt; / Div & gt;
There are five colors to color:
- First word: #EE7F00
- Second word: #EA650D
- Third word: # E64415
- Fourth word: # EA 650D
- 5 words: #EE7F00
Six to twelve words
Any help would be greatly appreciated.
Div>
This is the beginning:
// iterate throught .title spans $ ('title'). Get text from each (function (idx) {// span var txt = $ (this) .text (); // Sir word words = txt.split (""); var html by dividing words separated by one space Repeat through the words = ""; // and repeat them (var i = 0; i & lt; words.length; i ++) {span style = "color: '+ receive color (i) + ';' & Gt; '+ word [i] +' & lt; / span & gt; ';} // Write $ Html $ (this). Html (html);}); Function getColor (i) {var color = ""; If (I == 0) color = "#EE 7F00"; And if (I == 1) color = "# EA650D"; Else if (i == 2) color = "# E64415"; Else if (i == 3) color = "# EA650D"; Else if (i == 4) color = "#EE7F00"; Else if (i> = 5 & amp; amp;; & lt; = 11) get getColor (Math Floor (i-5) / 2); And if (i> = 12) returns the color (Math Floor (I-12) / 3)); The color of the return; }
If I am receiving color arguments correctly, 100% is not fixed, so the getColor function is to determine the color based on the current word index.
This is a bella:
No comments:
Post a Comment