$(function() { // 时间轴 var timernum = 0; var space = 210; // 移动间距 var length = $('.timer-scale-cont').length, numl; // 分辨率 if (document.body.clientwidth > 1500) { numl = length - 4 } else if (document.body.clientwidth < 1500 && document.body.clientwidth > 1234) { numl = length - 3 } else if (document.body.clientwidth < 1234 && document.body.clientwidth > 954) { numl = length - 2 } else if (document.body.clientwidth < 954) { numl = length - 1 } // 点击左侧 $('.timer-left').on('click', function() { if (timernum > 0) { timernum -= 1; movel(timernum, numl) } tags(timernum); }) // 点击右侧 $('.timer-right').on('click', function() { if (timernum < length - 1) { timernum += 1; tags(timernum); } movel(timernum, numl) }) // 点击年 $('.time-circle').each(function(index) { $(this).on('click', function() { timernum = index; movel(timernum, numl) tags(timernum); }) }) function tags(num) { $('.timer-scale-cont').eq(num).addclass('hov').siblings().removeclass('hov'); $('.shaft-detail-cont').eq(num).show().siblings().hide(); } function movel(num, len) { if (num < len) { moveleft = -num * space; $('.timer-scale').animate({ left: moveleft }, 700); } } })