【发布时间】:2014-02-07 10:18:53
【问题描述】:
我正在使用 jquery cycle1 插件制作幻灯片,在图像之间进行淡入淡出过渡,没有上一个或下一个控件。我需要在此滑块上叠加文本,该滑块会根据幻灯片显示的内容更改颜色。
我对 jQuery 不是很流利,所以我很难使用文档来操作可用的选项。感谢this post 和this one,我已经走到了这一步,但显然,颜色会在之前或之后略有变化,具体取决于我使用之前还是之后。如何在幻灯片同时更改文本颜色?
注意:我必须使用cycle 1 插件,因为我的网站使用的是jQuery 1.3.2,没有升级的希望。
这里是fiddle,代码如下。提前感谢您的帮助!
这是我的 html:
<div id="text">this is some text over the slider</div>
<div id="switch-it">
<div id="slide1">
<a href="link1.html">
<img src="hp_hero_010114_01.jpg" height="500" width="980" border="0" />
</a>
</div>
<div id="slide2">
<a href="link2.html">
<img src="hp_hero_010114_02.jpg" height="500" width="980" border="0"/>
</a>
</div>
</div><!--//END switch-it-->
这里是 jQuery
$(document).ready(function(){
$('#switch-it').after('<div id="switch" class="switch">').cycle({
fx: 'fade',
speed: 800,
timeout: 500,
cleartypeNoBg: true,
height:'500px',
width:'980px',
pager:'#switch',
pause:1,
before: function (prev, current, opts) {
var current_id = $(current).attr('id');
if( current_id.match("slide1")){
$('#text').css('color','white');
}
else if( current_id.match("slide2")){
$('#text').css('color','red');
}
else if( current_id.match("slide3")){
$('#text').css('color','blue');
}
else if( current_id.match("slide4")){
$('#text').css('color','green');
}
},
pagerAnchorBuilder: function(index, el) {
return '<a href="#">•</a>'; // whatever markup you want
}
});
});
【问题讨论】:
标签: javascript jquery html css