
$('.tabs ul li').eq(0).click(function(){
$('body,html').animate({scrollTop: $('#tab1').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(1).click(function(){
$('body,html').animate({scrollTop: $('#tab2').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(2).click(function(){
$('body,html').animate({scrollTop: $('#tab3').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(3).click(function(){
$('body,html').animate({scrollTop: $('#tab4').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(4).click(function(){
$('body,html').animate({scrollTop: $('#tab5').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(5).click(function(){
$('body,html').animate({scrollTop: $('#tab6').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(6).click(function(){
$('body,html').animate({scrollTop: $('#tab7').offset().top-30+'px'}, 800);
});
$('.tabs ul li').eq(7).click(function(){
$('body,html').animate({scrollTop: $('#tab8').offset().top-30+'px'}, 800);
});
1 hippoboy 2016-01-20 10:51:01 +08:00 确定长度之后递归或者遍历? |
2 wesley 2016-01-20 11:01:11 +08:00 $('.tabs ul li').click(function(){ $('body,html').animate({scrollTop: $('#tab'+($(this).index()+1)).offset().top-30+'px'}, 800); }); |
3 sleepwater 2016-01-20 11:07:38 +08:00 $('.tabs ul li').on('click', function() { $('body,html').animate({scrollTop: $('#tab' + ($(this).index() + 1)).offset().top - 30 + 'px'}, 800); }); |
4 chairuosen 2016-01-20 11:12:49 +08:00 这种东西应该把 target 写到 html 里,$('[click-target]').click(function(){ some code scroll to $( $(this).attr('click-target') ); }) |
5 shiye515 2016-01-20 11:48:37 +08:00 via Android 如果维护这个项目的人连这个都不会优化了,那就放弃治疗吧,这肯定不是项目里最奇葩的代码 |
6 Zzzzzzzzz 2016-01-20 11:50:57 +08:00 这段就应该直接写成事件委托的. |