我正在尝试使用Unicode编写泰卢固语文本,以便根据声音将文本更改为多种颜色进行突出显示。为此,我使用HTML5和JS。
<div class="pa">ప</div>
<div class="paa">పా</div>
通过使用
$("#paa").animate({ color: "blue" }, 500);
我可以改变整个字母的颜色,但现在我想突出显示其中的一部分。请建议如何实现?
我正在尝试使用Unicode编写泰卢固语文本,以便根据声音将文本更改为多种颜色进行突出显示。为此,我使用HTML5和JS。
<div class="pa">ప</div>
<div class="paa">పా</div>
$("#paa").animate({ color: "blue" }, 500);
我可以改变整个字母的颜色,但现在我想突出显示其中的一部分。请建议如何实现?
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>
运行代码片段,并看到绿色的文本从上到下填充为蓝色。
没有添加前缀,后续浏览器不需要它 :)
这是一件可行的事情,但对于所有语言来说并不容易。在下面的例子中,我为某些字母着色。
http://jsfiddle.net/07hh3z2n/5/提示是使用 CSS 获得一个没有宽度的 inline-block
。
.phantom {
display: inline-block;
color: red;
width: 0;
overflow: visible;
}
<span>
作为包装器,那么可以保持文本流。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>
$('.searchme').highlight('high');
示例