我有一个问题,如果按下一个键,如何保持/继续循环。我想用案例 1 / 案例 2 / 案例 3 和案例 4 为页面设置动画,但我想知道如果再次按下该键(并再次......)如何继续循环。我在这里读到了循环,但我就是想不通。
在此先感谢,这是我的代码:
var counter = 0;
$(document).bind('keydown', function(e) {
if(e.which == 37 || e.which == 39) {
counter++;
switch(counter) {
case 1:
$('#maikeximu,#dossier').stop()
.animate({
height: "toggle",
}, 1200, function() {
$('html,body').animate({
scrollTop: $("#maikeximu").next().offset().top
}, 1000);
});
break;
case 2:
$("#gal,#dossier, #viz").stop()
.animate({
height: "toggle",
}, 1200, function() {
$('html,body').animate({
scrollTop: $("#gal").next().offset().top
}, 1000);
});
break;
case 3:
$('#viz,#dossier').stop()
.animate({
height: "toggle",
}, 1200, function() {
$('html,body').animate({
scrollTop: $("#dossier").next().offset().top
}, 1000);
});
break;
case 4:
$('#maikeximu, #gal,#dossier').stop()
.animate({
height: "toggle",
}, 1200, function() {
$('html,body').animate({
scrollTop: $("#maikeximu").offset().top
}, 0);
});
break;
counter = 0;
return;
}
};
});
我希望更多地了解循环(对我来说是个大问题):)