我需要使用 jquery 为网站创建自定义滑块。到目前为止,如果我单击一个按钮,我已经设法让它按照我想要的方式运行,但我想实现一个自动计时器,以便幻灯片在 5 秒后切换。
这是我的 JS 代码:
function MasterSlider() {
//store the current button ID
var current_button = $(this).attr('id');
//reset all the items
$('#slider ul a').removeClass('slider-button-active');
//set current item as active
$(this).addClass('slider-button-active');
//scroll it to the right position
$('.mask').scrollTo($(this).attr('rel'), 850);
//Check which button is pressed and fade the text accordingly
if(current_button == "slider_item1")
{
$('#slider h3').fadeOut().removeClass('caption_active');
$('#slider_caption1').fadeIn().addClass('caption_active');
}
else if(current_button == "slider_item2")
{
$('#slider h3').fadeOut().removeClass('caption_active');
$('#slider_caption2').fadeIn().addClass('caption_active');
}
else if(current_button == "slider_item3")
{
$('#slider h3').fadeOut().removeClass('caption_active');
$('#slider_caption3').fadeIn().addClass('caption_active');
}
//disable click event
return false;
}
//append click event to the UL list anchor tag
$('#slider ul a').click(MasterSlider);
提前致谢!