我在我的网站上将此脚本用于我的 Slider。 我希望 slider 在选项卡之间自动切换。我让它处理点击事件,但我需要它以设定的时间间隔在选项卡之间旋转。 任何人都可以帮助我会很好吗?
JS:
$(document).ready(function() {
//Default Action
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the rel attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active content
return false;
});
});
HTML:
<div style="float:left; width:290px; height:243px;">
<ul class="tabs">{loop:navigation}
<li> <a style="color:#fff; text-decoration:none;" href="#tab{navigation:id}">
{navigation:headline}<br />
{navigation:text}
</a>
</li>{stop:navigation}</ul>
</div>
<div style="float:left; width:558px; height:243px;">{loop:specials}
<div id="tab{specials:id}" class="tab_content"> <a href="http://{specials:url}" title=""><img src="{page:path}{specials:pic}" width="{specials:width}" height="{specials:height}" alt="" /></a>
</div>
{stop:specials}
</div>
最佳答案
从这里开始(或快速修复)的最简单方法是在一个时间间隔内触发点击功能:
setInterval(function(){ $("ul.tabs li").click(); }, 5000); // 5 seconds
.click()
和.trigger('click')
是一样的,大家可以多用自己喜欢的。
关于javascript - 在我的淡出脚本中包含自动切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21636263/