$(function() { //banner toggle var myLi = $('.banner ul li').eq(0).clone(); var myTag = $(myLi); $('.banner ul').append(myTag); var olKey = 0; var ulKey = 0; var timer01 = null; function myFn(){ olKey++; if(olKey > 2){ olKey = 0; } $('.banner ol li').eq(olKey).addClass('current').siblings().removeClass('current'); ulKey++; if(ulKey > 3){ ulKey = 1; $('.banner ul').css('left','0'); } var move = ulKey * - 100; $('.banner ul').stop().animate({'left':''+ move+'%'}, 500); } $('.btnR').click(function(event) { myFn(); }); $('.btnL').click(function(event) { olKey--; if(olKey < 0){ olKey = 2; } $('.banner ol li').eq(olKey).addClass('current').siblings().removeClass('current'); ulKey--; if(ulKey < 0){ ulKey = 2; $('.banner ul').css('left','- 400%'); } var move = ulKey * - 100; $('.banner ul').stop().animate({'left':''+ move +'%'}, 500); }); $('.banner ol li').click(function(event) { myFn(); }); timer01 = setInterval(function(){ myFn(); }, 4000); $('.banner').hover(function() { clearInterval(timer01); }, function() { timer01 = setInterval(function(){ myFn(); }, 4000); }); //goto top $(window).scroll(function() { if ($(window).scrollTop() > ($(window).height() / 2)) { $('.toTop').show(); } else { $('.toTop').hide(); } }); $('.toTop').click(function(event) { $('body,html').stop().animate({ 'scrollTop': '0px' }, 500); $('nav').css({ 'top': '0px' }); }); });