4

I am trying to write a telugu text using uni codes so that I can highlight the text by changing into multiple colours according to sound. for that I am using html5 and js

<div  class="pa">&#3114;</div>
<div  class="paa">&#3114;&#3134;</div>

by using

$("#paa").animate({ color: "blue" }, 500); 

I can change the entire colour of the letter but now I want to highlight some part of that letter . Please suggest how it can be done.???

brennanyoung
  • 6,243
  • 3
  • 26
  • 44
priyanka
  • 197
  • 2
  • 12
  • 1
    Part of the letter or part of the word? if part of the word just style the words with: `aw` etc. so that you can select all the spans differently. – Persijn Mar 19 '15 at 12:43
  • 1
    Hi Persijn,Thank you for this. But I want to highlight a part of letter only. – priyanka Mar 19 '15 at 12:45
  • What you can do is, you can search for some text or word from the entire letter, and replace that searched result with some specific element and class, and give css to that class to highlight particular part. – Mox Shah Mar 19 '15 at 12:46
  • If you mean "part of that WORD" then please correct it in your post. – Puneet Mar 19 '15 at 12:46
  • Or better you post your some sample letter with example that which part you want to be highlighted. – Mox Shah Mar 19 '15 at 12:47
  • as u r seeing the letters in my post, the difference between the two letters which was appearing ( ప పా) is the part which i wanted to highlight. – priyanka Mar 19 '15 at 12:51
  • Hi Moksh Shah, I tried that also by taking #
    and replacing the needed part , bt the letter is not suitable for my requirement.
    – priyanka Mar 19 '15 at 13:02
  • 1
    possible duplicate of [Is it possible to apply CSS to half of a character?](http://stackoverflow.com/questions/23569441/is-it-possible-to-apply-css-to-half-of-a-character) – James Thorpe Mar 19 '15 at 13:03
  • You cannot change the colour of *parts of a letter*, at least not easily. – Sverri M. Olsen Mar 19 '15 at 13:03
  • 1
    can you quote an example with ENGLISH Letters ,because solution will remain the same.and by that question will be clear to all – Shekhar Pankaj Mar 19 '15 at 13:03
  • your JS should be `$(".paa").animate...` not `$("#paa").animate...` – Harold Ship Mar 19 '15 at 13:08
  • in css it is not yet usable but take a look at this: http://nimbupani.com/using-background-clip-for-text-with-css-fallback.html – G-Cyrillus Mar 19 '15 at 13:10
  • 2
    No i have taken that paa as id not as class soo nothing is wrong with that. – priyanka Mar 19 '15 at 13:12
  • 1
    Can you post something with live example, so that would help us to understand more about your requirement. – Mox Shah Mar 19 '15 at 13:15

4 Answers4

3

there is a few css tricks to fake the background-clip:text; or something alike SVG.

span {
  position:relative;
  color:green;
}
span:before {
  position:absolute;
  top:0;
  left:0;
  overflow:hidden;
  content:attr(data-text);
  color:blue;
  height:0.7em;
  overflow:hidden;
  animation: txtclr 4s infinite;
}
p {
  background:yellow;
  color:rgba(128, 0, 128 , 0.5);
  font-size:2em;
  font-weight:bold;
  background:linear-gradient(to bottom,lightgray 50%,yellow 50%);
  display:table;/* demo purpose to shrink to text size*/
  box-shadow:inset -3em 0 rgba(100,100,100,0.5);
  
}
@keyframes txtclr {
  0% {
    height:50%;
  }
  25%,75%{
    height:0;
    width:0;
  }
  50%{
    height:100%;
  }
}
<p><span data-text="my text">my text</span> and some other text </p>

run code snippet and see green text filling with blue from top to bottom.

no prefix added, later browser do not need it :)

G-Cyrillus
  • 101,410
  • 14
  • 105
  • 129
  • For this question I want to add an image for refference, but as my reputation is low It is not allowing me to post. – priyanka Mar 25 '15 at 12:02
2

Do you mean something like this? uses only css to flow the text over it, no need for javascript in this example ;-) but you could always switch out classes with desired effect and such.

What it does is uses the transition property that allows it to animate inbetween different css states after an event like hover, click active and such.

To highlight a part of a letter, you need to add that HTML element twice. What I have done with coloured and plain. This also counts for individual letters. You need to set them to an absolute position and wrap them in a relative div. By doing that they will position themselves absolutely to the top left location(in my example) of the the relative wrapper div. This way you can keep text flow if you use a <span> for a wrapper fo example

Then you set one to width 0 or to whatever width you want it to cover up half the other letter

In my example only half of the Y is red, the other half(half ish) is not red.

If you wish to cover a top half you can play with height.

http://jsfiddle.net/L9L8L966/1/

    #container {
        font-size:40px;
        position:relative;
        background-color:#CCC;
        width:450px;
        height:40px;
    }
    #coloured {
        position:absolute;
        z-index:2;
        top:0px;
        left:0px;
        display:block;
        width:0%;
         -webkit-transition: width 1s ease-in-out;
        -moz-transition: width 1s ease-in-out;
        -o-transition: width 1s ease-in-out;
        transition: width 1s ease-in-out;
        color:red;
        overflow:hidden;
    }
    #container:hover #coloured {
        width:100%;
    }
    #plain {
        position:absolute;
        z-index:1;
        width:100%;
        display:block;
        top:0px;
        left:0px;
        color:black;
    }


    
<div id="container">
        <div id="coloured">
            abcdefghijklmnopqrstuvwxyz
        </div>
        <div id="plain">
            abcdefghijklmnopqrstuvwxyz
        </div>
    </div>
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
2

It is feasible, but not easy with all languages. In the following example, I colored accents on certain letters. http://jsfiddle.net/07hh3z2n/5/

The hint is to use a CSS to get an inline-block with no width.

.phantom {
    display: inline-block;
    color: red;
    width: 0;
    overflow: visible;
}

If the part of the letter you want to highlight is an existing unicode char, this will work fine. Otherwise, you can try to use (or create) a special font with the parts of letters to highlight.

Tolokoban
  • 2,297
  • 14
  • 17
1

If you want to highlight on the fly in your code, I would use a javascript frame work Highlight.js . it is very light and easy to work with. Here is a fiddle with jquery and knockout sample: $('.searchme').highlight('high'); sample

Vlad
  • 474
  • 4
  • 8