我使用这个基于a href id
值的 jQuery 函数将每个 4 个 div 切换 10 秒。
计时器工作正常,它每 10 秒更改 4 个 div,但是当用户单击特定 div 时,它不会导航到特定 div 并停留在给定时间段(例如 10 秒)并从当前 div 进入下一个 div 而不是它根据计时器值进入 div。
任何人都可以帮我解决这个问题吗?
$(function() {
$("a.menu").click(function() {
$("div.featuredposts_content").hide();
$($(this).attr('href')).show();
return false;
});
});
$(function() {
var counter = 0,
divs = $('#cat1, #cat2, #cat3,#cat4');
function showDiv() {
divs.hide() // hide all divs
.filter(function(index) {
return index == counter % 4;
}) // figure out correct div to show
.show('fast'); // and show it
counter++;
}; // function to loop through divs and show correct div
showDiv(); // show first div
setInterval(function() {
showDiv(); // show next div
}, 15 * 1000); // do this every 10 seconds
});