$('#scrollbar').tinyscrollbar(); $('#scrollbar2').tinyscrollbar({ axis: 'x'}); $(function(){ var time_count=$('#scrollbar2 .overview ul li a').length; $('#scrollbar2 .overview ul li:even').css({'width':'44px'}); $('#scrollbar2 .overview ul li:odd').css({'width':'20px','padding':'0 10px','fontweight':'200'}); $('#scrollbar2 .overview').css('width',(time_count*84).tostring()+'px'); var speed=500; var time_bar_length=$('.scrollbar .track').css('width'); var bar_permove=parseint(parseint(time_bar_length)/time_count); var i=0; $('#scrollbar2 .overview a').click(function(){ var year_index=$(this).index('#scrollbar2 .overview a'); var bar_left=bar_permove*year_index; $('#scrollbar2 .overview').find('a').removeclass('on'); $(this).addclass('on'); $('#scrollbar2 .thumb').animate({'left':bar_left.tostring()+'px'},speed); //点击年份后滑动条的滑动效果 $('#scrollbar2 .overview').animate({'left':(-year_index*84+bar_left).tostring()+'px'},speed); //点击年份后,时间条的滑动效果 $('.loading').show(); $('#year_events').attr('src',''); settimeout(function(){$('.loading').hide();$('#year_events').attr('src',$(this).attr('href'))},200); }); $('#scrollbar2 .thumb').mousedown(function(){ i=1; }); $('#scrollbar2 .thumb').mouseup(function(){ bar_drag(); }); $('body').mouseup(function(){ if(i==1){ bar_drag(); i=0; } }); function bar_drag(){ $('#scrollbar2 .overview').find('a').removeclass('on'); var year_index=(parseint($('#scrollbar2 .thumb').css('left'))/bar_permove).tofixed(0); var bar_left=bar_permove*year_index; var curr_url=$('#scrollbar2 .overview a:eq('+year_index+')').attr('href'); $('#scrollbar2 .overview a:eq('+year_index+')').addclass('on'); $('#scrollbar2 .thumb').animate({'left':bar_left.tostring()+'px'},speed); //点击年份后滑动条的滑动效果 $('#scrollbar2 .overview').animate({'left':(-year_index*84+bar_left).tostring()+'px'},speed); //点击年份后,时间条的滑动效果 $('.loading').show(); $('#year_events').attr('src',''); settimeout(function(){$('.loading').hide();$('#year_events').attr('src',curr_url);},200); i=1; } });