'use strict'; //轮播 var playpre = 0, playindex = playpre, $play = $('.index_play').children(), $index_num = $('.index_num'), playlength = $play.length, timeout; $play.eq(playpre).addclass('hide'); $play.eq(playindex).removeclass('hide'); $index_num.text((playindex + 1) + '/' + playlength); function preplay() { playindex--; if(playindex < 0) { playindex = playlength - 1; } toplay(1); } function nextplay() { playindex++; if(playindex === playlength) { playindex = 0; } toplay(2); } function toplay(num) { $index_num.text((playindex + 1) + '/' + playlength); if(num === 2) { tweenmax.fromto($play.eq(playpre), 0.5, { x: '0%' }, { x: '-100%' }); $play.eq(playindex).removeclass('hide'); tweenmax.fromto($play.eq(playindex), 0.5, { x: '100%' }, { x: '0%', oncomplete: function() { clearinterval(timeout); timeout = settimeout(function() { nextplay(); }, 4000); } }); playpre = playindex; } else { tweenmax.fromto($play.eq(playpre), 0.5, { x: '0%' }, { x: '100%' }); $play.eq(playindex).removeclass('hide'); tweenmax.fromto($play.eq(playindex), 0.5, { x: '-100%' }, { x: '0%', oncomplete: function() { clearinterval(timeout); timeout = settimeout(function() { nextplay(); }, 4000); } }); playpre = playindex; } } $('.index_left_btn').on('click', function() { clearinterval(timeout); preplay(); }); $('.index_right_btn').on('click', function() { clearinterval(timeout); nextplay(); }); $('.index_yuyue_btn').on('click', function() { window.open("/guide/show.php?lang=cn&id=28"); }); timeout = settimeout(function() { nextplay(); }, 4000); //导航栏切换 (function() { var $l = $('.cars_left_btn'), $r = $('.cars_right_btn'), $index_cars = $('.index_cars'); $l.addclass('hide'); $l.on('click',function(){ $l.addclass('hide'); $r.removeclass('hide'); $index_cars.animate({'left':'0px'},200); }); $r.on('click',function(){ $l.removeclass('hide'); $r.addclass('hide'); $index_cars.animate({'left':'-230px'},200); }); })();