jQuery插件:文本旋转器,改变颜色

时间:2016-02-24 23:22:42

标签: javascript jquery html css

jQuery插件页面:https://github.com/peachananr/simple-text-rotator

我的小提琴:https://jsfiddle.net/jzhang172/8msf91wa/

请检查我的外部小提琴,而不是这里的代码,由于某种原因它不能在这里工作。

我想用自定义css更改某些单词的颜色,但无法了解如何:

$(document).ready(function(){
$(".rotate2").textrotator({
  animation: "dissolve", // You can pick the way it animates when rotating through words. Options are dissolve (default), fade, flip, flipUp, flipCube, flipCubeUp and spin.
  separator: ",", // If you don't want commas to be the separator, you can define a new separator (|, &, * etc.) by yourself using this field.
  speed: 2000 // How many milliseconds until the next word show.
});
});
span.color1{
  color:red !important;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/simple-text-rotator/1.0.0/simpletextrotator.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/simple-text-rotator/1.0.0/jquery.simple-text-rotator.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Hey, <span class="rotate2">Friend, <span class="color1">sir</span>, ma'am</span>

1 个答案:

答案 0 :(得分:1)

正如您在source中看到的那样,插件使用$.text().rotate2元素转换为文本字符串,因此您的所有颜色标记都会被静默丢弃。 似乎不可能将样式应用于单个条目。