$('.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 年 1 月 20 日
确定长度之后递归或者遍历?
|
2
wesley 2016 年 1 月 20 日
$('.tabs ul li').click(function(){
$('body,html').animate({scrollTop: $('#tab'+($(this).index()+1)).offset().top-30+'px'}, 800); }); |
3
sleepwater 2016 年 1 月 20 日
$('.tabs ul li').on('click', function() {
$('body,html').animate({scrollTop: $('#tab' + ($(this).index() + 1)).offset().top - 30 + 'px'}, 800); }); |
4
chairuosen 2016 年 1 月 20 日
这种东西应该把 target 写到 html 里,$('[click-target]').click(function(){ some code scroll to $( $(this).attr('click-target') ); })
|
5
shiye515 2016 年 1 月 20 日 via Android
如果维护这个项目的人连这个都不会优化了,那就放弃治疗吧,这肯定不是项目里最奇葩的代码
|
6
Zzzzzzzzz 2016 年 1 月 20 日
这段就应该直接写成事件委托的.
|