我有以下 jQuery
<script type="text/javascript">
jQuery(function(){
jQuery('.link1').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle1').show();
jQuery('#arrow').css({top: '0px'});
});
jQuery('.link2').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle2').show();
jQuery('#arrow').css({top: '42px'});
});
jQuery('.link3').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle3').show();
jQuery('#arrow').css({top: '84px'});
});
jQuery('.link4').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle4').show();
jQuery('#arrow').css({top: '125px'});
});
jQuery('.link5').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle5').show();
jQuery('#arrow').css({top: '166px'});
});
jQuery('.link6').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle6').show();
jQuery('#arrow').css({top: '207px'});
});
});
jQuery(function(){
jQuery("#toggle-links ul > li > a").click(function(e){
e.preventDefault();
jQuery("#toggle-links ul > li > a").addClass("selected").not(this).removeClass("selected");
});
});
</script>
并且需要添加一个函数,该函数将按 link1、link2、link3...每 3 秒的顺序运行单击函数,直到到达 link6,然后它将循环回 link1,如果用户将鼠标悬停在带有 id 的 div 上#holder 该函数将停止运行,直到鼠标移出。我对此有点困惑,有什么想法吗?
Try:
var interval = null;
jQuery(function(){
interval = setInterval(callFunc, 3000);
});
function callFunc(){
jQuery('.link1, .link2, .link3').trigger('click');
}
您可以随时通过调用以下命令来停止自动点击:
clearInterval(interval);
要按顺序调用它们,您可以像这样修改代码:
jQuery('.link1').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle1').show();
jQuery('#arrow').css({top: '0px'});
// click link2
jQuery('.link2').trigger('click');
});
jQuery('.link2').click(function(){
jQuery('.hide-div').hide();
jQuery('.toggle2').show();
jQuery('#arrow').css({top: '42px'});
// click link3
jQuery('.link3').trigger('click');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)